原 This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the
版权声明:本文为博主原创文章,请尊重他人的劳动成果,转载请附上原文出处链接和本声明。
本文链接:https://www.91mszl.com/zhangwuji/article/details/1302
场景:我是在一个serviceA 里面调用了serviceB 里面的方法,然后我又在serviceB里面调用了serviceA里面的方法,报错信息如下:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'expandAlgorithmController':
Unsatisfied dependency expressed through field 'expandAlgorithmService'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'expandAlgorithmServiceImpl': Bean with name 'expandAlgorithmServiceImpl' has been injected into other beans [businessExpandServiceImpl]
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.
错误原因:serviceA和serviceB循环依赖了,spring在初始化bean的时候就不知道先初始化哪个bean就会报错。
解决方法:在注入service的时候加一个@Lazy 注解就可以了。
参考资料:https://blog.csdn.net/u011546347/article/details/85230362
2021-02-02 18:12:41 阅读(3102)
名师出品,必属精品 https://www.91mszl.com