首先,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不能是多例才行。