環(huán)繞通知加上后,advice最后的after和afterRetuning輸出順序問題
@沒加環(huán)繞通知的輸出:
MoocAspect before.
AspectBiz biz.
MoocAspect afterReturning.
MoocAspect after.
@加了環(huán)繞通知后的輸出:
MoocAspect before.
MoocAspect around 1.
AspectBiz biz.
MoocAspect around 2.
MoocAspect after.
MoocAspect afterReturning.
【溫馨提示:Java、Jsp、Android、JS等編程愛好者可以聯(lián)系Q:28554482,互相學(xué)習(xí),共同進(jìn)步!】
2018-07-20
Spring官方的說法是,在同一個切面內(nèi),同類型(前/后)的通知順序是不確定的。因為通過反射確定類中聲明順序(這句話的意思,我也不理解)。
見官方文檔說明(同時給出了排序的建議):
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.
2017-06-10
我測試了下,發(fā)現(xiàn)當(dāng)有around配置時,after和afterReturning的執(zhí)行順序與他們在XML文件中配置的順序是相反的,原理我也沒有搞清楚。