Spring3.0 How to configure multiple transaction managers (that is, to manipulate multiple data sources)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.