atomikos + mysql 事物不回滚【求助!!!!!!!!!!!!!!】

lishi6038 2016-07-10 01:18:01
我的mysql数据库引擎是
+------------------------+--------+
| Variable_name | Value |
+------------------------+--------+
| default_storage_engine | InnoDB |
+------------------------+--------+
操作单个数据库都无法回滚。。。
关键的配置文件和测试代码如下:
spring-mvc bean的配置文件:
<bean id="mutilDB1" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="db1"/>
<property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
<property name="poolSize" value="3" />
<property name="reapTimeout" value="20000"/>
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="100" />
<property name="borrowConnectionTimeout" value="30" />
<property name="testQuery" value="select 1 from dual" />
<property name="maintenanceInterval" value="60" />
<property name="xaProperties">
<props>
<prop key="user">${jdbc.username}</prop>
<prop key="password">${jdbc.password}</prop>
<prop key="URL">${jdbc1.url}</prop>
</props>
</property>
</bean>

<bean id="mutilDB2" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName" value="db2" />
<property name="xaDataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
<property name="poolSize" value="3" />
<property name="reapTimeout" value="20000"/>
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="100" />
<property name="borrowConnectionTimeout" value="30" />
<property name="testQuery" value="select 1 from dual" />
<property name="maintenanceInterval" value="60" />
<property name="xaProperties">
<props>
<prop key="user">${jdbc.username}</prop>
<prop key="password">${jdbc.password}</prop>
<prop key="URL">${jdbc2.url}</prop>
</props>
</property>
</bean>

<bean name="jdbcTemplate1" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="mutilDB1" />
</bean>

<bean name="jdbcTemplate2" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="mutilDB2" />
</bean>

<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
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="3000" />
</bean>

<!-- spring 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="userTransaction" ref="atomikosUserTransaction" />
<property name="allowCustomIsolationLevels" value="true"/>
</bean>

<!-- 使用annotation定义事务,对于要加入事物的类,只需对该类加 @Transactional -->
<tx:annotation-driven transaction-manager="transactionManager" />



测试代码如下:
Controller关键代码:
@ResponseBody
@RequestMapping("testDb1")
public Json login() throws Exception {
// 参数校验
Json resultJson = new Json();
userService.updateDB1();
return resultJson;
}


Service关键代码:
@Autowired
private JdbcTemplate jdbcTemplate1;
.....
@Transactional(rollbackFor=Exception.class)
public void updateDB1()throws Exception{
jdbcTemplate1.update("update t_user set name='66666' where id=1");
throw new RuntimeException();
}


运行的结果是 数据库的字段会被修改,事物无法回滚
...全文
228 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lishi6038 2016-07-10
  • 打赏
  • 举报
回复
问题已经解决,是spring-mvc配置扫描的问题

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧