Spring Multi-transaction configuration (multiple transaction Manager) and how to use it

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/><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

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.