终于明白springboot为什么还会因为循环依赖报错
首先,spring是已经解决循环依赖的问题的:https://blog.csdn.net/Apeopl/article/details/90146337但是有时候还是会报错,(代码不报错,启动的时候报错):The dependencies of some of the beans in the application context form a cycle:AppController↓Inqui
首先,spring是已经解决循环依赖的问题的:https://blog.csdn.net/Apeopl/article/details/90146337
但是有时候还是会报错,(代码不报错,启动的时候报错):
The dependencies of some of the beans in the application context form a cycle:
AppController
↓
InquiryService
┌─────┐
| AppService
↑ ↓
| AppVTVService
└─────┘
然后看到另一篇文章 图解 Spring 循环依赖:https://mp.weixin.qq.com/s/FtbzTMxHgzL0G1R2pSlh-A
终于明白造成报错的原因其实是因为使用了多例:@Scope("prototype")
@Service("appService")
@Scope("prototype")
public class AppService{
@Resource
private AppVTVService appVTVService ;
...
}
然后经过我的实验,发现只有AppService使用多例的时候才会报错。
只要AppService不是多例,不管AppVTVService是不是多例都不会报错。
那就说明,在这个循环圈里,第一个被调用的service不能是多例才行。
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)