今天遇到了一个循环依赖的问题:
之前一直听说过循环依赖,面试的时候也经常问循环依赖的问题,具体解决方案就是spring的三级缓存可以解决循环依赖问题
找了一下,说spring解决不了两种情况的循环依赖:
1. 非单例
2. 构造器注入
巧了,我的代码都不符合,所以按道理说,我的循环依赖问题spring完全可以自己解决的
想着看看源码吧,到底什么情况,但是我源码太不熟了,根本不知道入口在哪里,怎么看,只知道在populatBean的方法里面可以解决循环依赖的问题
重点来了,我又看了一遍报错信息,下面是
Action:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
翻译过来就是:
注意:
不鼓励依赖循环引用,