Spring循环依赖问题修复

拆分的时候,把错误都处理完后,准备把工程起起来,发现弹簧的循环依赖问题。具体问题如下

Bean with name 'userManager' has been injected into other beans [daoAuthenticationProvider] in its raw version as part of a circular reference, but has eventually been wrapped (for example as part of auto-proxy creation). 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 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.

1.怀疑配置文件的问题
但是在原工程中并没有这个问题,所以一开始怀疑是配置文件的配置不一样,百度了一下这个错误

beanFactory.setAllowRawInjectionDespiteWrapping(true);

看网上说这个配置了,对于循环依赖的这个错误就会解决掉。但是在两个工程里搜索了一下都没有发现这个配置过。
于是只能调试进去看看
2.调查查看分析
2.1 spring引用的bean和注入的bean不一致导致的这个错误
由于在原工程里是可以循环引用的,所以对工程和新工程都在初始化这两个循环引用的位置进行了调试
然后发现最后两边走的逻辑不一样的在以下的代码里:

原文链接

猜你喜欢

转载自blog.csdn.net/weixin_40581617/article/details/84875207
今日推荐