PDA

View Full Version : Error when inject one dataSource instance to multiple transactionAdvisor beans



good12
Jun 26th, 2007, 05:25 PM
I'm using Spring 2.0.6 and got a question regarding AOP:

When I define 2 transactionAdvisor beans in the same ApplicationContext- one uses jdbc transactionManager, the other uses hibernate transactionManager, and both transactionManager beans use the same dataSource (hsqlPoolDataSource, singleton scope), I got the following error:

org.springframework.beans.factory.BeanCurrentlyInC reationException: Error creating bean with name 'hsqlPoolDataSource': Bean with name 'hsqlPoolDataSource' has been injected into other beans [jdbcTransactionManager] in its raw version as part of a circular reference, but has eventually been wrapped (for example as part of auto-proxy creation). 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.

So my question is: is it Spring restriction that the same datasource instance can't be injected to more than one transactionAdvisor (or interceptor) or it's just the way I config is not correct?

(The reason I'm defining the two transactionAdvisor beans in one context is for pure experiment purposes. And I also noticed that the issue goes away when the dataSource bean is defined with a "prototype" scope.)

Appreciate it if someone can explain. Thanks!

********* config ***********

<bean id="annotationTransactionAdvisor"
class="org.springframework.transaction.interceptor.Transa ctionAttributeSourceAdvisor">
<constructor-arg ref="annotationTransactionInterceptor"/>
</bean>

<bean id="annotationTransactionInterceptor"
class="org.springframework.transaction.interceptor.Transa ctionInterceptor">
<property name="transactionManager" ref="hibernateTransactionManager"/>
<property name="transactionAttributeSource" ref="attributesTransactionAttributeSource"/>
</bean>

<bean id="declarativeTransactionAdvisor"
class="org.springframework.transaction.interceptor.Transa ctionAttributeSourceAdvisor">
<constructor-arg ref="declarativeTransactionInterceptor"/>
</bean>

<bean id="declarativeTransactionInterceptor"
class="org.springframework.transaction.interceptor.Transa ctionInterceptor">
<property name="transactionManager" ref="jdbcTransactionManager"/>
<property name="transactionAttributeSource"
ref="methodMapTransactionAttributeSource"/>
</bean>

...

<bean id="hsqlPoolDataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" scope="prototype">
<property name="driverClassName" value="${jdbc.driverClassName.hsql}"/>
<property name="url" value="${jdbc.url.hsql}"/>
<property name="username" value="${jdbc.username.hsql}"/>
<property name="password" value="${jdbc.password.hsql}"/>
...
</bean>

******** config over ************

good12
Jun 27th, 2007, 02:17 PM
For the above case, there is a logging aspect defined on the dataSource bean. The error happens only when this AOP on the dataSource bean is enabled. Is this because the sequence of the dataSource bean initialization and the AOP application in undetermined?