记一次springmvc+mybatis事物管理错误(无法回滚)

无法回滚的时间过程

使用了spring mvc+mybatis时抛出异常无法回滚,因为使用的纯java配置所以和网上的教程略有不同之后配合官方文档解决。

解决方法

引用了spring官方文档的一句话

@EnableTransactionManagement and tx:annotation-driven/ look for @Transactional only on beans in the same application context in which they are defined. This means that, if you put annotation-driven configuration in a WebApplicationContext for a DispatcherServlet, it checks for @Transactional beans only in your controllers and not in your services. See MVC for more information.

大概意思是要把注解了@Transactional的类和你的controller(调用者)要放置在一个容器中,所以controller,service和@EnableTransactionManagement都要注册在同一个容器内。

参考我的情况

我的问题在于将Controller放置在了一个容器而service(被注解@Transactional的类)放置在了另外一个容器,所以导致事物无法回滚。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值