前言

今天再写完一个业务,部署服务器项目时报错:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'deviceShelfProductController': Injection of resource dependencies failed; nested exception is 
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 
'deviceShelfProductServiceImpl': Bean with name 'deviceShelfProductServiceImpl' has been injected into 
other beans [tradeServiceImpl] 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.

其中,红色标注英文的意思为循环引用,也就是说我在deviceShelfProductServiceImpl中引用注入了tradeServiceImpl,而在tradeServiceImpl中又引用注入了deviceShelfProductServiceImpl,这种情况叫做循环依赖。

解决办法的话:

1.可以将业务代码转移至其中一个业务类中,不要两个类互相引用

2.业务代码可能过于繁琐,不好转移,那么可以使用注解@Lazy进行延迟加载,即可避免循环依赖


版权声明:文章转载请注明来源,如有侵权请联系博主删除!
最后修改:2019 年 12 月 25 日 11 : 53 AM
如果觉得我的文章对你有用,请随意赞赏