ERROR--The dependencies of some of the beans in the application context form a cycle

The dependencies of some of the beans in the application context form a cycle

场景:

启动Spring Boot项目时报循环依赖错误:The dependencies of some of the beans in the application context form a cycle

原因分析:

应用程序上下文中某些bean的依赖关系形成了一个循环

从异常信息可以看出,这是循环依赖问题。这种通常会出现在两个类注入Bean时互相使用了构造函数注入对方。Spring IoC容器在运行时检测到此循环引用就会报错。

在SpringBoot多模块项目中,两个项目互相引入对方的依赖,就会报这样的错误。

解决方案:

方案: 直接根据自己需要,让他们不要互相依赖就行了。
选择报循环依赖的地方右键选择diagrams

接着

然后就可以看到你文件夹下所有的类

右键选择Show Dependencis

就可以查看到所有类依赖的情况,我这里就能清楚的看出哪里相互引用了

清除其中一个依赖后问题解决

参考博客:http://t.zoukankan.com/liyhbk-p-14230598.html

posted @ 2022-08-24 22:37  Li-Xiaolei  阅读(9864)  评论(0)    收藏  举报