spring aop 和Transaction一起使用执行顺序问题

在开发中遇到,aop拦截事物方法,先执行了,自己写的切面,Transaction还没提交

原因:spring Transaction也是aop实现,spring 先执行了自己定义的切面aop

解决方法:设置aop执行顺序,order越小越先执行

<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" order="0"/>

@Component
@Aspect
@Order(1)
public class YourAspect

 

 

网上摘抄了一段各注解执行顺序,待测

Spring 中通知的类型:

Around     org.aopalliance.intercept.MethodInterceptor                栏截对目标对象方法的调用 
Before      org.springframework.aop.MethodBeforAdvice             在目标方法被调用之前调用    
After          org.springframework.aop.AfterReturningAdvice          当目标方法被调用之后调用

Thorws    org.springframework.aop.ThrowsAdvice                       当目标方法抛出异常时调用

程序正常执行顺序:

执行前 -环绕通知                                              Around

执行前 - 通知                                                    Before

POINT - 切入点 方法前执行                               @Before

POINT - 切入点 环绕方法前执行                       @Around

POINT - 切入点 方法后执行                               @AfterReturning

POINT - 切入点 环绕方法后执行                       @Around

执行后 - 通知                                                    After        

执行后 - 环绕通知                                            Around

程序抛出异常执行顺序:

执行前 -环绕通知                                              Around

执行前 - 通知                                                    Before

POINT - 切入点 方法前执行                               @Before

POINT - 切入点 环绕方法前执行                       @Around

切入点异常处理通知                                             @AfterThrowing

异常处理通知                                                          Thorws

转载于:https://my.oschina.net/yugj/blog/615396

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值