梦编猿
2016-04-19 10:39
@没加环绕通知的输出:
MoocAspect before.
AspectBiz biz.
MoocAspect afterReturning.
MoocAspect after.
@加了环绕通知后的输出:
MoocAspect before.
MoocAspect around 1.
AspectBiz biz.
MoocAspect around 2.
MoocAspect after.
MoocAspect afterReturning.
【温馨提示:Java、Jsp、Android、JS等编程爱好者可以联系Q:28554482,互相学习,共同进步!】
Spring官方的说法是,在同一个切面内,同类型(前/后)的通知顺序是不确定的。因为通过反射确定类中声明顺序(这句话的意思,我也不理解)。
见官方文档说明(同时给出了排序的建议):
When two pieces of advice defined in the same aspect both need to run at the same join point, the ordering is undefined (since there is no way to retrieve the declaration order via reflection for javac-compiled classes). Consider collapsing such advice methods into one advice method per join point in each aspect class, or refactor the pieces of advice into separate aspect classes - which can be ordered at the aspect level.
我测试了下,发现当有around配置时,after和afterReturning的执行顺序与他们在XML文件中配置的顺序是相反的,原理我也没有搞清楚。
Spring入门篇
268787 学习 · 963 问题
相似问题