Spring由于属性的重复注入引发的org.springframework.beans.factory.BeanCurrentlyInCreationException

问题描述
通过spring配置文件对dataSource属性进行注入时报以下错误:

Exception in thread "main" org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dbSources': Bean with name 'dbSources' has been injected into other beans [txManager] 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.

解决思路
该问题的出现是因为对象循环引用形成闭环而造成的异常。此处是因为某一个属性在xml配置文件中被多次注入,应该修改代码避免这种状况

解决方案
此案例被多次注入属性名为dbSources,那么在使用dbSources的配置语句中我是
这样写的:


        
        
        
        
    
    
	
        
        
    

此处的Transactional中有dbSources属性,由于expression="execution(* .(…))的存在,会使我项目下所有包的中的java文件中dbSources都会被注释,报错xml文件。

 

修改为

 

也就是将execition中的位置修改成具体的类再指定方法

你可能感兴趣的:(Spring由于属性的重复注入引发的org.springframework.beans.factory.BeanCurrentlyInCreationException)