Announcement Announcement Module
Collapse
No announcement yet.
Multiple Transaction manager issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple Transaction manager issue

    I have some doubts regarding the multiple transaction manager issue, I have two spring config file defined two spring configuration manager.

    One file

    Code:
      <tx:advice id="txAdvice" transaction-manager="transactionManager1">
     <bean id="transactionManager1" class="org.springframework.jdbc.DataSourceTransactionManager">
        ...
    
      </bean>
    Another file
    Code:
      <tx:advice id="txAdvice" transaction-manager="transactionManager2">
     <bean id="transactionManager2" class="org.springframework.jdbc.DataSourceTransactionManager">
        ...
    
      </bean>
    Both of them was loaded into spring context, Now I have a service class, I didn't use the qulifier to indicate the transaction manager to use, I am wondering which transaction manager spring will going to use. Randomly pick up one or what?

    Code:
    public class TransactionalService {
    
    @Transactional
    public void setSomething(String name) { ... }
    
    @Transactional
    public void doSomething() { ... }
    
    
    }

  • #2
    First off, you have both <tx:advice> definitions with same id. It means that one overrides another. You should use <aop:advisor> in combination with <tx:advice> definition. @Transactional annotation works in combination with <tx:annotation-driven/>.
    If you have multiple transaction managers, use @Transactional("resource1") where <bean id="txManager"...><qualifier value="resource1"/></bean> is defined.
    If you want to know the exact way how Spring determines transaction manager for annotated method, read through TransactionAspectSupport#determineTransactionManag er method.

    Comment

    Working...
    X