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/><BeanID= "TransactionManager1"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager"> < Propertyname= "DataSource"ref= "Datasource1"></ Property> <Qualifiervalue= "Datasource1tx"/></Bean><BeanID= "TransactionManager2"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager"> < Propertyname= "DataSource"ref= "Datasource2"></ Property> <Qualifiervalue= "Datasource2tx"/></Bean>
Use @transactional ("Datasource1tx") and @transactional ("Datasource2tx") to distinguish the specific use of a transaction manager
Public class Transactionalservice { @Transactional ("Datasource1tx") publicvoid SetSomethingInDatasource1 () {...} @Transactional ("Datasource2tx") publicvoid DoSomethingInDatasource2 () {...}}
Or, use the Transactin Manager's bean name directly:
@Transactional("transactionManager1")
If using @transactional (), the equivalent of 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
Spring3.0 How to configure multiple transaction managers (that is, to manipulate multiple data sources)