Distributed transaction configuration in spring3.x

Source: Internet
Author: User

Because the use of spring3.x has been for some time, the original transaction configuration is basically based on the same data source (can use a connection, in the data operation to specify multiple database operations, also be able to rollback, transaction submission, basically implement a distributed transaction processing), today specifically with the Atomikos transaction configuration , a simple test, because Atomikos this configuration data source, with the connection pool, the performance of the connection pool is not specifically tested, the original C3P0 transaction configuration removed, this is to be tested tomorrow.

Dependent Java open source packages, automatically downloaded with maven:

My configuration

<properties>
<atomikos-version>3.9.3</atomikos-version>
</properties>

<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-jdbc</artifactId>
<version>${atomikos-version}</version>
</dependency>
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-jms</artifactId>
<version>${atomikos-version}</version>
</dependency>

Now write the atomikos+spring JDBC configuration for reference in future projects

<!--database Cb_base--

<!--database Cb_base--
<bean class= "Com.atomikos.jdbc.AtomikosDataSourceBean"
Init-method= "Init" destroy-method= "Close" id= "Datasourcebase" >
<!--Set unique name for this DataSource-
<property name= "Uniqueresourcename" ><value>mysql/${BasesDB.DBName}</value></property>
<!--Set Xadatasource class name-->
<property name= "Xadatasourceclassname" value= "Com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"/>
<property name= "Xaproperties" >
<props>
<prop key= "User" >${jdbc.basesUser}</prop>
<prop key= "Password" >${jdbc.basesPassword}</prop>
<prop key= "url" >${jdbc.basesJdbcUrl}</prop>
</props>
</property>
<!--set properties for DataSource connection pool--
<property name= "poolsize" value= "${jdbc.minpoolsize}"/>
<!--management Connection occupied time--
<!--If you do not set this value, Atomikos uses the default of 300 seconds (that is, 5 minutes), then when processing a large amount of data read, once more than 5 minutes, will be thrown like Resultset is close error-
<property name= "Reaptimeout" ><value>20000</value></property>
</bean>



<!--database Cb_files--
<bean class= "Com.atomikos.jdbc.AtomikosDataSourceBean"
Init-method= "Init" destroy-method= "Close" id= "Datasourcefile" >
<property name= "Uniqueresourcename" ><value>mysql/${FilesDB.DBName}</value></property>
<!--Set Xadatasource class name-->
<property name= "Xadatasourceclassname" value= "Com.mysql.jdbc.jdbc2.optional.MysqlXADataSource"/>
<property name= "Xaproperties" >
<props>
<prop key= "User" >${jdbc.filesUser}</prop>
<prop key= "Password" >${jdbc.filesPassword}</prop>
<prop key= "url" >${jdbc.filesJdbcUrl}</prop>
</props>
</property>
<!--set properties for DataSource connection pool--
<property name= "poolsize" value= "${jdbc.minpoolsize}"/>
<!--management Connection occupied time--
<!--If you do not set this value, Atomikos uses the default of 300 seconds (that is, 5 minutes), then when processing a large amount of data read, once more than 5 minutes, will be thrown like Resultset is close error-
<property name= "Reaptimeout" ><value>20000</value></property>
</bean>

<bean id= "Atomikostransactionmanager" class= "Com.atomikos.icatch.jta.UserTransactionManager"
Init-method= "Init" destroy-method= "Close" >
<property name= "Forceshutdown" value= "true"/>
</bean>

<bean id= "atomikosusertransaction" class= "COM.ATOMIKOS.ICATCH.JTA.USERTRANSACTIONIMP" >
<property name= "transactiontimeout" value= "/>"
</bean>


<!--JTA Transaction Manager--
<bean id= "Jtatransactionmanager" class= "Org.springframework.transaction.jta.JtaTransactionManager" >
<property name= "usertransaction" ref= "Atomikosusertransaction"/>
<property name= "TransactionManager" ref= "Atomikostransactionmanager"/>
<property name= "Allowcustomisolationlevels" value= "true"/>
</bean>

<tx:annotation-driven transaction-manager= "Jtatransactionmanager" order= "/>"


<!--settings JdbcTemplate--
<bean id= "Basesjdbctemplate" class= "Org.springframework.jdbc.core.JdbcTemplate" >
<property name= "DataSource" >
<ref bean= "Datasourcebase"/>
</property>
</bean>

<bean id= "Filesjdbctemplate" class= "Org.springframework.jdbc.core.JdbcTemplate" >
<property name= "DataSource" >
<ref bean= "Datasourcefile"/>
</property>
</bean>


The other is the basic JDBC configuration.

<!--database Operations base class--

<bean id= "Basesbasedao" class= "Com.xxxx.bases.persistent.dao.impl.VDAOImpl" >
<description> Basic DAO Interface </description>
<property name= "JdbcTemplate" ref= "Basesjdbctemplate"/>
<property name= "DbName" value= "${basesdb.dbname}"/>
</bean>

<bean id= "Filesbasedao" class= "Com.xxxx.files.persistent.dao.impl.VDAOImpl" >
<description> Basic DAO Interface </description>
<property name= "JdbcTemplate" ref= "Filesjdbctemplate" >
</property>
<property name= "DbName" value= "${filesdb.dbname}" >
</property>
</bean>



Distributed transaction configuration in spring3.x

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.