【异常】——org.springframework.beans.factory.BeanCreationException:...part of a circular reference....

前言 

今天再写完一个业务,部署服务器项目时报错:
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进行延迟加载,即可避免循环依赖

发布了74 篇原创文章 · 获赞 960 · 访问量 72万+

猜你喜欢

转载自blog.csdn.net/qq_37141773/article/details/98485695