admin管理员组文章数量:1530059
今天写代码的时候遇到一个报错
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'A': Bean with name 'A' has been injected into other beans [B] 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
经过科学上网排查,发现是spring 循环依赖了。如:
@Component
public class ServiceA {
@Autowired
private ServiceB serviceB;
public ServiceA() {
System.out.println("init serviceA");
}
}
@Component
public class ServiceB {
@Autowired
ServiceA serviceA;
public ServiceB() {
System.out.println("innit ServiceB");
}
}
互相依赖于对方,实例化时导致报错。
解决:我目前并没有解决循环依赖的问题,而是避免循环依赖。
如何解决sping的循环依赖,待定。
本文标签: wrappedeventuallyspingfinalbeans
版权声明:本文标题:sping循环依赖:but has eventually been wrapped. This means that said other beans do not use the final 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1726654260a1080067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论