Atomikos Configuring multiple data sources JTA managing transactions

Source: Internet
Author: User

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&lt ;/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

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.