SpringBoot--AOP多个切⾯织⼊同时织⼊⼀个⽅法时的执⾏顺序
  在做基于aop的拦截controller⼊参并记录⽇志和基于aop的⾃定义注解来实现校验参数这两个功能时遇到了这个问题,就是当两个或多个aop同时作⽤于同⼀个⽅法时的执⾏顺序是什么。答案是,根据这个切⾯的设定顺序,这个设定的顺序越⼩则越先执⾏,⽬前设定顺序主要有三种⽅式:
1. 实现Ordered接⼝,重写getOrder⽅法。
@Component
@Aspect
public class MessageQueueAopAspect implements Ordered{
@Override
public int getOrder(){
// TODO Auto-generated method stub
return2;
}
}
2. 使⽤order注解指定顺序。
@Component
@Aspect
@Order(1)
public class MessageQueueAopAspect1{
...
}
3. 通过配置⽂件配置设定顺序。
<aop:config expose-proxy="true">
<aop:aspect ref="aopBean" order="0">
<aop:pointcut id="testPointcut"  expression="@)"/>
<aop:around pointcut-ref="testPointcut" method="doAround"/>
</aop:aspect>
</aop:config>
spring aop应用场景  经实验确定,确实是order越⼩越是最先执⾏,但更重要的是最先执⾏的最后结束。下⾯我们通过看⼀个图会更直观:
  Spring aop就是⼀个同⼼圆,要执⾏的⽅法为圆⼼,最外层的order最⼩。从最外层按照AOP1、AOP2的顺序依次执⾏doAround⽅法,doBefore⽅法。然后执⾏method⽅法,最后按照AOP2、AOP1的顺序依次执⾏doAfter、doAfterReturn⽅法。也就是说对多个AOP来说,先before的,⼀定后after。
  然后下⾯两个更清晰些:
1. 同⼀aspect,不同advice的执⾏顺序
2. 不同aspect,advice的执⾏顺序