I've the following setting
@Configuration
@ConditionalOnProperty(name = "my.enabled", havingValue = "true", matchIfMissing = true)
public class MyMvcConfigurer implements WebMvcConfigurer {
private final MyInterceptor myInterceptor;
...
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(myInterceptor);
}
}
@Component
@ConditionalOnProperty(name = "my.enabled", havingValue = "true", matchIfMissing = true)
public class MyInterceptor implements HandlerInterceptor {
private final MyService myService;
public MyInterceptor(MyService myService) {
this.myService = myService;
}
@Service
@ConditionalOnProperty(name = "my.enabled", havingValue = "true")
public class MyServiceImpl implements MyService {
private final MyClient myClient;
// private final ObjectProvider<MyClient> myClient; <-- This does work
@FeignClient
@ConditionalOnProperty(name = "my.enabled", havingValue = "true")
public interface MyClient {
...
}
This lead to the following error:
The dependencies of some of the beans in the application context form a cycle:
┌─────┐
| myWebMvcConfigurer
↑ ↓
| myProtectedInterceptor
↑ ↓
| myServiceImpl
↑ ↓
| org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration
└─────┘
It works when I switch to private final ObjectProvider<MyClient> myClient; in the service implementation.
Why is this happening? I'm not sure how the service implementation forces a dependency to the custom WebMvcConfigurer. Any why it's only happening when the FeignClient is in the class.