关于aop是什么以及怎么使用aop我这里不在赘述。
主要是针对aop上遇到的小细节整理一下,以防自己忘记
1.代理模式
springboot的aop默认是用cglib代理,methodinvocationprocceedingpointcut中的ProxyMethodInvocation会传递一个cglibInvocation的class
如果把springboot的aop代理改成动态代理,那么可以采用动态代理的切点都会采用动态代理,没有借口实现的类(controller)会采用cglib
2.通知执行顺序
1.around_1进入
2.before_1
3.around_2进入
4.before_2
5.执行方法
6.around_2结束
7.after_2
8.afterreturning_2
9.around_1结束
10.after_1
11.afterreturning_1
对同一个切点进行aop拦截,两个通知谁先执行不一定
如果想要指定顺序请用@order注解
当抛异常的时候,around的结束和afterreturning不会执行,其他正常执行
1.around_1进入
2.before_1
3.around_2进入
4.before_2
5.执行方法
6.after_2
7.after_1
try{
try{
//@Before
method.invoke(..);
}finally{
//@After
}
//@AfterReturning
}catch(){
//@AfterThrowing
}