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