如何解决为什么 FeignClient 会创建对 WebMvcAutoConfiguration 的循环依赖?
我有以下设置
@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",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 {
...
}
这会导致以下错误:
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
└─────┘
当我在服务实现中切换到 private final ObjectProvider<MyClient> myClient;
时它会起作用。
为什么会这样?我不确定服务实现如何强制依赖于自定义 WebMvcConfigurer。为什么它只在 FeignClient 在类中时发生。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。