SpringBoot事务 | 未生效 | 无效 | 不生效 | 不回滚 | 不起作用
如果你使用了 @Transactional 和 @EnableTransactionManagement 没有生效,那么你看看在事务注解包含的方法内是否使用try-catch了。默认事务回滚对于try-catch的代码不会生效,如果必须try-catch又要事务生效,则需要在catch块内手动回滚。但是不推荐这么写,推荐Service层将异常往上抛,Controller层去捕获处理。

关于手动回滚,你可以看这里

TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//进行手动回滚

//设置回滚点
Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
....
//回滚到savePoint
TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);

 

当然我遇到的只是事务不生效的原因之一,可能并不适用你所遇到的情况,仅作为备忘使用,如果能恰巧帮到你那就呱唧一下

相关文章:

  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2021-05-27
  • 2021-06-08
  • 2022-12-23
猜你喜欢
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
相关资源
相似解决方案