亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

環繞通知加上后,advice最后的after和afterRetuning輸出順序問題

@沒加環繞通知的輸出:

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,互相學習,共同進步!】

正在回答

2 回答

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.


0 回復 有任何疑惑可以回復我~

我測試了下,發現當有around配置時,after和afterReturning的執行順序與他們在XML文件中配置的順序是相反的,原理我也沒有搞清楚。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Spring入門篇
  • 參與學習       268802    人
  • 解答問題       1026    個

為您帶來IOC和AOP的基本概念及用法,為后續高級課程學習打下基礎

進入課程

環繞通知加上后,advice最后的after和afterRetuning輸出順序問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號