Multiple transaction managers with @Transactional annotation

后端 未结 2 1396
醉话见心
醉话见心 2020-12-29 08:31
  1. We have base generic manager which is inherited by all managers. Base manager is annotated with @Transactional annotations.

  2. There are 2 groups of t

相关标签:
2条回答
  • 2020-12-29 08:50

    I guess you can define @Transactional at class-level

    @Service
    @Transactional(readOnly = false, value="txManager2") 
    class BillingManagerImpl ....
    
    0 讨论(0)
  • 2020-12-29 09:02

    There is the possibility to create your own annotations as shortcuts for @Transactional(value="tx1"). (These can be used at class or method level)

    from the reference documentation:

    For example, defining the following annotations

    @Target({ElementType.METHOD, ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Transactional("order")
    public @interface OrderTx {
    }
    
    @Target({ElementType.METHOD, ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Transactional("account")
    public @interface AccountTx {
    }  
    

    allows us to write the example from the previous section as

    public class TransactionalService {
    
        @OrderTx
        public void setSomething(String name) { ... }
    
        @AccountTx
        public void doSomething() { ... }
      }
    
    0 讨论(0)
提交回复
热议问题