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 ************
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 ************