How to configure transaction management for working with 2 different db in Spring?

前端 未结 4 771
无人共我
无人共我 2020-12-02 10:49

I have 2 databases (MySql and HSQLDB). I configured 2 data sources and 2 EntityManagerFactory beans. I can also configure 2 correspondent JpaTransactionManager beans.

4条回答
  •  伪装坚强ぢ
    2020-12-02 11:25

    Declare your without transaction-manager attribute, declare qualifiers for transaction managers like this:

    
        
        
    
    

    Use this qualifier in @Transactional as a value to select one of transaction managers:

    @Transactional("txManager1")
    

    or, with more properties:

    @Transactional(value = "txManager1", readOnly = true)   
    

提交回复
热议问题