Most projects require only one transaction manager. However, some projects are best used with multiple transaction managers to improve efficiency, or to have multiple disparate and disparate data sources. Smart Spring's transactional management has taken this into account, first defining multiple transactional manager separately and assigning different values to the qualifier property Then specify the value of the TransactionManager qualifier property or use the bean name directly when you need to use @transactional annotations. Examples 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>
public class Transactionalservice { @Transactional ("DATASOURCE1TX") public void SetSomethingInDatasource1 () { ... } @Transactional ("Datasource2tx") public void DoSomethingInDatasource2 () {...}}
Or, use the Transactin Manager's bean name directly:
@Transactional("transactionManager1")
If you use @transactional (), it is equivalent to using the default transaction Mananger name, namely: @Transactional ("TransactionManager")
Reference: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/# Tx-multiple-tx-mgrs-with-attransactional
(original article, reprint please specify the blog from Clement-xu )
Copyright NOTICE: This article is the original article, reprint please indicate the CSDN blog which is transferred from Clement-xu.
Spring Multi-transaction configuration (multiple transaction Manager) and how to use it