接手了一个老项目,代码贼乱,没有注释。项目启动时报错如下:
Error creating bean with name 'AAA': Bean with name 'AAA' has been injected into other beans [BBB] in its raw version as part of a circular reference, but has eventually been wrapped. 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.
报错原因:循环依赖。A和B互相依赖。
解决办法:在注入时加上@Lazy注解。
import groovy.lang.Lazy; @Autowired @Lazy private XXXService XXXService;
参考: