开发者社区> 问答> 正文

spring+mybatis+druid+atomikos+mysql分布式事务?400报错

 

使用的是spring+mybatis+druid+atomikos+mysql,

xml配置如下,确实在执行到service层的save*的方法时有日志:

INFO : com.atomikos.icatch.imp.BaseTransactionManager - createCompositeTransaction ( 300000 ): created new ROOT transaction with id com.atomikos.spring.jdbc.tm0000100111

然后在报错的时候,不管是自己抛的运行时异常还是插入已有主键故意报错时都会打印:

INFO : com.atomikos.icatch.imp.CompositeTransactionImp - rollback() done of transaction com.atomikos.spring.jdbc.tm0000100111

但是奇怪的是并没有回滚,数据依然插入了数据库 。

现在由自己查阅资料已知的是:

1.数据库是innodb。支持事务

2.事务配置应该没问题

3.service确实是在spring中加载,controller在spring-servlet的xml中加载。

下面是配置文件,pointcut切点没问题,是我删的。

请大神解答,到底是为什么可以打印日志,但是不回滚

 

<aop:config  expose-proxy="true">
		<aop:pointcut expression="execution(* (..))"这句修改了,保证正确
			id="datasource-pointcut" />
		<aop:advisor pointcut="execution(*..*Service.*(..))"这句修改了,保证正确
			advice-ref="txAdvice" />
		<aop:aspect ref="dynamicDataSourceAspectJ">
			<aop:before method="switchDataSource" pointcut-ref="datasource-pointcut" />
		</aop:aspect>
</aop:config>

<tx:advice id="txAdvice" transaction-manager="jtaTransactionManager">
		<tx:attributes>
			<tx:method name="insert*" propagation="REQUIRED" />
			<tx:method name="save*" propagation="REQUIRED"  />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="edit*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="remove*" propagation="REQUIRED" />
			<tx:method name="autoCommit*" propagation="REQUIRES_NEW" />
			<tx:method name="*" propagation="NOT_SUPPORTED" read-only="true" />
		</tx:attributes>
	</tx:advice>
	<bean id="jtaTransactionManager"
		class="org.springframework.transaction.jta.JtaTransactionManager"
		scope="prototype">
		<property name="transactionManager" ref="atomikosTransactionManager" />
		<property name="userTransaction" ref="atomikosUserTransaction" />
		<property name="allowCustomIsolationLevels" value="true" />
		<property name="globalRollbackOnParticipationFailure" value="true" />
	</bean>

 

展开
收起
爱吃鱼的程序员 2020-06-08 17:07:06 659 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    问题已解决

    啥问题?分享一下呗

    求分享一下,目前也是这个问题

    求分享,遇到类似问题

    才看到,什么问题呢?

    问题怎么解决的,能否告知一下呢

    选择innodb

    就是选择的InnoDB
    2020-06-08 17:07:19
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
workshop专场-微服务专场-开发者动手实践营-微服务-Spring Cloud Alibaba 微服务全家桶体验 立即下载
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载

相关镜像