org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'publicAccountInfoServiceImpl':Injection of resource dependencies failed; nested exception is
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name
'publicAccountInfoDao': Bean with name 'publicAccountInfoDao' has been injected into other beans
[publicAccountService] 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
overeager type matching - consider using 'getBeanNamesForType' with the 'allowEagerInit' flag turned off
异常大概如上。
然后我们先说一下什么是依赖循环,比如:我现在有一个ServiceA
需要调用ServiceB
的方法,那么ServiceA
就依赖于ServiceB
,那在ServiceB
中再调用ServiceA
的方法,就形成了循环依赖。Spring在初始化bean的时候就不知道先初始化哪个bean就会报错。
看了上述是不是觉得很简单呢?但是呢,我的代码并不是如此,出现问题的地方有两个PublicAccountInfoServiceImpl
和PublicAccountService
,这两个类都注入了PublicAccountInfoDao
,PublicAccountInfoDao
这个类只与数据库交互,并没有引入上面两个类,所以并非上述所谓的依赖循环。
@Service
public class PublicAccountInfoServiceImpl {
@Resource
priavte PublicAccountInfoDao publicAccountInfoDao;
}
@Service
public class PublicAccountService{
@Autowried
priavte PublicAccountInfoDao publicAccountInfoDao;
}
这些是上述两个类的部分代码,然而这些代码呢,也是很早之前的代码了。并不是笔者写的,这就问题很大,不知道怎么下手解决,然后我在注入PublicAccountInfoDao上面打上了@Lazy的注解就没问题了。暂时不知道原因,正在研究~~~~