Configure two DataSource
<bean id= "DataSource" class= "Com.atomikos.jdbc.AtomikosDataSourceBean" > <property name= "Uniqueresourcenam E "><value>yw</value></property> <property name=" Xadatasourceclassname "value=" Com.mysql.jdbc.jdbc2.optional.MysqlXADataSource "/> <property name=" xaproperties "> <props > <prop key= "URL" >${jdbc.url}</prop> <prop key= "user" >${jdbc.userna me}</prop> <prop key= "password" >${jdbc.password}</prop> </props> </property> <property name= "poolsize" ><value>1</value></property> &L T;property name= "Minpoolsize" value= "2"/> <property name= "maxpoolsize" value= "ten"/> </bean> <!--test-<bean id= "DataSource2" class= "Com.atomikos.jdbc.AtomikosDataSourceBean" > <pro Perty name= "Uniqueresourcename" ><value>ds2</value></property> <property name= "Xadatasourceclassname" value= " Com.mysql.jdbc.jdbc2.optional.MysqlXADataSource "/> <property name=" xaproperties "> <props > <prop key= "URL" >${jdbc.url2}</prop> <prop key= "user" >${jdbc.usern ame2}</prop> <prop key= "password" >${jdbc.password2}</prop> </props> </property> <property name= "Poolsize" ><value>1</value></property> <property name= "Minpoolsize" value= "2"/> <property name= "maxpoolsize" value= "ten"/> </bean& Gt
JdbcTemplate Configuration
<bean id= "JdbcTemplate" class= "org.springframework.jdbc.core.JdbcTemplate" > <property name= " DataSource "> <ref local=" DataSource "/> </property> </bean> <!--test data source-- > <bean id= "JdbcTemplate2" class= "org.springframework.jdbc.core.JdbcTemplate" > <property Name = "DataSource" > <ref local= "DataSource2"/> </property> </bean> <bean ID = "Basedao" class= "Com.szy.base.BaseDao" > <property name= "JdbcTemplate" > <ref bean= " JdbcTemplate "/> </property> </bean>
The second data source can be injected with a spring annotation.
public class BaseDao2 { @Resource (name = "JdbcTemplate2") protected JdbcTemplate Jdbctemplate2=null ; private int total=0; public void Settotal (Int. total ) { this.total = Total ;}}
Configure Transaction Management
<!--start configuring JTA transactions--<bean id= "Atomikostransactionmanager" class= "com.atomikos.icatch.jta.UserTransacti Onmanager "init-method=" Init "destroy-method=" close "> <property name=" Forceshutdown "><value>true< ;/value></property> </bean> <bean id= "atomikosusertransaction" class= "Com.atomikos.icatch.jta". Usertransactionimp "> <property name=" transactiontimeout "><value>300</value></property > </bean> <bean id= "TransactionManager" class= "Org.springframework.transaction.jta.JtaTransactionMan Ager "> <property name=" TransactionManager "> <ref local=" Atomikostransactionmanager "/> </property> <property name= "usertransaction" > <ref local= "atomikosusertransaction"/&G T </property> </bean> <!--define transactions with annotation--<tx:annotation-driven transaction-manager= "TransactionManager"Proxy-target-class= "true"/>
So it's done.
Only to record problems that have been encountered.
Atomikos Configuring multiple data sources JTA managing transactions