概述
问题重现
定义一个类A
(1)实现SmartApplicationListener接口
(2)在重写的onApplicationEvent方法上定义@Async注解
(3)在类中注入其它服务的Feign接口对象
示例如下:
@Slf4j
@Component
public class A implements SmartApplicationListener {
@Autowired
private FeignX feignX;
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
return eventType == XXXEvent.class;
}
@Async
@Override
public void onApplicationEvent(ApplicationEvent event) {
}
}
满足上述3个条件后,启动服务出现如下错误:
Bean with name 'a' has been injected into other beans [xxx.feign.FeignX] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off
问题原因
待考究
解决方案
不实现SmartApplicationListener接口,改用@EventListener注解定义处理方法
@Slf4j
@Component
public class A {
@Autowired
private FeignX feignX;
@EventListener
@Async
@Override
public void onApplicationEvent(XXXEvent event) {
}
}
最后
以上就是隐形玉米为你收集整理的实现SmartApplicationListener并在方法上加上@Async注解,同时引入Feign接口对象导致循环依赖问题问题重现问题原因解决方案的全部内容,希望文章能够帮你解决实现SmartApplicationListener并在方法上加上@Async注解,同时引入Feign接口对象导致循环依赖问题问题重现问题原因解决方案所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复