How to configure multiple transaction managers in Spring3.0: spring3.0 transactions
Spring configures multiple transaction managers (that is, operating multiple data sources)
Most projects only need one transaction manager. However, it is best to use multiple transaction managers for some projects to improve efficiency or to have multiple completely different and irrelevant data sources. Witty Spring's Transactional management has taken this into account. First, multiple transactional managers are defined and different values are specified for the qualifier attribute; specify the qualifier attribute value of TransactionManager or directly use the bean name when @ Transactional annotation is required. Example of configuration and code usage:
<tx:annotation-driven/><bean id="transactionManager1" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="datasource1"></property> <qualifier value="datasource1Tx"/></bean><bean id="transactionManager2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="datasource2"></property> <qualifier value="datasource2Tx"/></bean>
Use @ Transactional ("datasource1Tx") and @ Transactional ("datasource2Tx") to differentiate the specific use of a transaction manager.
public class TransactionalService { @Transactional("datasource1Tx") public void setSomethingInDatasource1() { ... } @Transactional("datasource2Tx") public void doSomethingInDatasource2() { ... }}
Alternatively, use the bean name of transpneumatic manager directly:
@ Transactional ("transactionManager1 ")
If @ Transactional () is used, the default transaction mananger name is used, that is, @ Transactional ("transactionManager ")
Reference: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#tx-multiple-tx-mgrs-with-attransactional
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!