0
votes

I defined two datasource in server.xml and i would like to use them with a jta transaction Manager.But how to releated the jndi and the transaction Manager?

here is server.xml

<dataSource jndiName="jdbc/db1" id="jdbc/db1" auth="Container"  type="javax.sql.XADataSource">
    <jdbcDriver libraryRef="DBLIB" javax.sql.XADataSource="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
    <properties databaseName="" URL="jdbc:mysql://ip:port/DB?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false" user="user" password="pwd" />
    <connectionManager id="jdbc/sqlPool" maxPoolSize="30" minPoolSize="20" connectionTimeout="180" reapTime="180" unusedTimeout="1800" agedTimeout="0" />
 </dataSource>

<dataSource jndiName="jdbc/db2" id="jdbc/db2" auth="Container"  type="javax.sql.XADataSource">
    <jdbcDriver libraryRef="DBLIB" javax.sql.XADataSource="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
    <properties databaseName="" URL="jdbc:mysql://ip:port/DB?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false" user="user" password="pwd" />
    <connectionManager id="jdbc/sqlPool" maxPoolSize="30" minPoolSize="20" connectionTimeout="180" reapTime="180" unusedTimeout="1800" agedTimeout="0" />
</dataSource>

here is applicationContext.xml

<!--jta-->
<bean id="jtaTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close" >
  <property name="forceShutdown" value="true"/>
</bean>
<bean id="userTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
  <property name="transactionTimeout" value="300"/>
</bean>

<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager">
  <property name="userTransaction" ref="userTransaction"/>
  <property name="transactionManager" ref="jtaTransactionManager"/>
  <property name="allowCustomIsolationLevels" value="true"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />

<jee:jndi-lookup id="datasource1" jndi-name="jdbc/db1"></jee:jndi-lookup>

<jee:jndi-lookup id="datasource2" jndi-name="jdbc/db2"></jee:jndi-lookup>

this question looks same with mine.But the transactionManager doesn't allow dataSource property Spring Transaction with JNDI and JPA transaction manager

1
Can i configure the datasource type with AtomikosDataSourceBean?Ran Ji

1 Answers

0
votes

At last

  1. configure the datasource with xadatasource
  2. user WebSphereUowTransactionManager
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager">
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />