Spring multiple @Transactional datasources

后端 未结 2 1278
耶瑟儿~
耶瑟儿~ 2020-12-08 23:11

    

        
相关标签:
2条回答
  • 2020-12-08 23:28

    More on the need for more than one transaction manager. You might be trying to do nested or separate transactions in sequence -- then you can use different propagation settings. You can achieve that with configuration using single transaction manager see Transaction propagation.

    0 讨论(0)
  • 2020-12-08 23:46

    You can specify which tx manager to use with @Transactional using the value attribute:

    A qualifier value for the specified transaction.

    May be used to determine the target transaction manager, matching the qualifier value (or the bean name) of a specific PlatformTransactionManager bean definition.

    For example:

    @Transactional("txManager1");
    

    Alternatively, you can use the more explicit TransactionProxyFactoryBean, which gives you finer-grained control over what objects gets proxied by what tx managers. This still uses the annotations, but it doesn't auto-detect beans, it's configured explicitly on a bean-by-bean basis.

    This normally isn't an issue, but it's not wise to have multiple transaction managers unless you have a very good reason to do so. If you find yourself needing two tx managers, it's usually better to see if you can make do with one. For example, if you have two data sources configured in your app server, you can incorporate both in a single JtaTransactionManager, rather than two seperate JpaTransactionManager or DataSourceTransactionmanagers.

    0 讨论(0)
提交回复
热议问题