1

Have 2 Transaction Mangers as follows

<bean id="transactionManager1"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource1" />
</bean>

<bean id="transactionManager2"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource2" />
</bean>

Both are the registered to AspectJ AnnotationTransactionManager as follows

 <bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" factory-method="aspectOf">
        <property name="transactionManager" ref="transactionManager1" />
    </bean>
 <bean class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" factory-method="aspectOf">
        <property name="transactionManager" ref="transactionManager2" />
    </bean>

and transaction enabled using annotations as follows-

<tx:annotation-driven transaction-manager="transactionManager1" mode="aspectj" />
<tx:annotation-driven transaction-manager="transactionManager2" mode="aspectj" />

This causes setting of transactionManager property of Abstract class - 'org.springframework.transaction.interceptor.TransactionAspectSupport to the last annotation transaction aspect bean created during server startup.

However not able to select TransactionManager at runtime using qualifiers. Does org.springframework.transaction.aspectj.AnnotationTransactionAspect asllow multiple transaction Managers?

Rehan
  • 929
  • 1
  • 12
  • 29
  • You can only have 1 `` and adding the `AnnotationTransactionAspect` doesn't add anything (it does the same as the ``. – M. Deinum Feb 22 '16 at 11:34
  • Thanks M. Deinum..Have never used AOP using aspectj. Could you please confirm if multiple transaction Managers can be handled using qualifiers when using aspect(in same way as we do for Spring AOP) – Rehan Feb 22 '16 at 13:23
  • In theory it should work, the Aspect uses the same base class, as the `TransactionInterceptor` and that base class contains all the functionality. – M. Deinum Feb 22 '16 at 14:06
  • M. Deinum- Have to justify removing AnnotationTransactionAspect . Is there any Spring Reference doc that states and AnnotationTransactionAspect do same thing. Trying to find it but not able to. Thanks – Rehan Feb 23 '16 at 08:16
  • No you would have to look at the code. `` is basically the shortcut for that, at least when mode is set to `aspectj`. – M. Deinum Feb 23 '16 at 08:28

0 Answers0