Spring 事务没生效的几种可能性。 will not be managed by Spring

Spring 事务没生效的几种可能性。 will not be managed by Spring,第1张

Spring 事务没生效的几种可能性。 will not be managed by Spring
  • 在非public 方法上使用事务 如 @Transactional protected void .. (原因 Spring 事务是基于AOP 实现的 在Spring 中 切点只能与public 方法匹配,也就是说Spring 的事务只支持可见度为public 的方法)

  • 在同一个类中没事务的方法调用了有事务的方法,事务也会失效,看下面的例子 ,调用testA ,testA 调用了testB ,testB 上的事务就会失效。 TransactionAspectSupport.currentTransactionStatus(); 可以看到当前事务的状态

    @Component
    public class Car {

    public void testA(){
        testB();
    }
    
    @Transactional
    public void testB(){
        TransactionAspectSupport.currentTransactionStatus();
    }
    

    }

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/724267.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存