atomikos事务问题

小番茄 发布于 2017/11/23 10:38
阅读 221
收藏 0
 

<?xml version="1.0" encoding="UTF-8" ?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:util="http://www.springframework.org/schema/util"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:jpa="http://www.springframework.org/schema/data/jpa"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd

http://www.springframework.org/schema/util

http://www.springframework.org/schema/util/spring-util-2.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.2.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/data/jpa

http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd">

<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">

<property name="transactionTimeout" value="300" />

</bean>

<bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">

<property name="userTransaction" ref="atomikosUserTransaction" />

</bean>

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

<!-- 配置数据源 -->

<bean id="dataSourceA" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">

<property name="uniqueResourceName" value="XA1DBMS" />

<property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />

<property name="xaProperties">

<props>

<prop key="URL">jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8</prop>

<prop key="user">root</prop>

<prop key="password">ligang</prop>

</props>

</property>

<property name="poolSize" value="3" />

<property name="minPoolSize" value="3" />

<property name="maxPoolSize" value="5" />

</bean>

<!-- 配置数据源 -->

<bean id="dataSourceB" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">

<property name="uniqueResourceName" value="XA2DBMS" />

<property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />

<property name="xaProperties">

<props>

<prop key="URL">jdbc:mysql://localhost:3306/test2?useUnicode=true&amp;characterEncoding=utf-8</prop>

<prop key="user">root</prop>

<prop key="password">ligang</prop>

</props>

</property>

<property name="poolSize" value="3" />

<property name="minPoolSize" value="3" />

<property name="maxPoolSize" value="5" />

</bean>

<bean id="jdbcTemplateA" class="org.springframework.jdbc.core.JdbcTemplate">

<property name="dataSource" ref="dataSourceA" />

</bean>

<bean id="jdbcTemplateB" class="org.springframework.jdbc.core.JdbcTemplate">

<property name="dataSource" ref="dataSourceB" />

</bean>

</beans>

atomikos分布式事务,采用以上配置事务能正常提交已经回滚,但是如果在运行期间只要调用存储过程就会报异常:Caused by: java.sql.SQLException: XAER_RMFAIL: The command cannot be executed when global transaction is in the  ACTIVE state

如果将配置改为:

 

<?xml version="1.0" encoding="UTF-8" ?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:util="http://www.springframework.org/schema/util"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:jpa="http://www.springframework.org/schema/data/jpa"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

http://www.springframework.org/schema/mvc

http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd

http://www.springframework.org/schema/util

http://www.springframework.org/schema/util/spring-util-2.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.2.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

http://www.springframework.org/schema/data/jpa

http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd">

<bean id="userTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">

<property name="transactionTimeout" value="300" />

</bean>

<bean id="springTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">

<property name="userTransaction" ref="userTransaction" />

</bean>

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

<!-- 配置数据源 -->

<bean id="dataSourceA" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean" init-method="init" destroy-method="close">

<property name="uniqueResourceName" value="XA1DBMS" />

<property name="url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8" />

<property name="user" value="root" />

<property name="password" value="ligang" />

<property name="driverClassName" value="com.mysql.jdbc.Driver" />

<property name="poolSize" value="3" />

<property name="minPoolSize" value="3" />

<property name="maxPoolSize" value="5" />

</bean>

<!-- 配置数据源 -->

<bean id="dataSourceB" class="com.atomikos.jdbc.nonxa.AtomikosNonXADataSourceBean" init-method="init" destroy-method="close">

<property name="uniqueResourceName" value="XA2DBMS" />

<property name="url" value="jdbc:mysql://localhost:3306/test2?useUnicode=true&amp;characterEncoding=utf-8" />

<property name="user" value="root" />

<property name="password" value="ligang" />

<property name="driverClassName" value="com.mysql.jdbc.Driver" />

<property name="poolSize" value="3" />

<property name="minPoolSize" value="3" />

<property name="maxPoolSize" value="5" />

</bean>

<bean id="jdbcTemplateA" class="org.springframework.jdbc.core.JdbcTemplate">

<property name="dataSource" ref="dataSourceA" />

</bean>

<bean id="jdbcTemplateB" class="org.springframework.jdbc.core.JdbcTemplate">

<property name="dataSource" ref="dataSourceB" />

</bean>

</beans>

这种方式就可以调用存储过程,有谁知道原因可以解答一下吗?我用的是mysql数据库

加载中
返回顶部
顶部