afrag  
          記錄學習和成長的歷程
          日歷
          <2009年8月>
          2627282930311
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345
          統計
          • 隨筆 - 9
          • 文章 - 5
          • 評論 - 2
          • 引用 - 0

          導航

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          •  

          積分與排名

          • 積分 - 10198
          • 排名 - 2381

          最新評論

          閱讀排行榜

          評論排行榜

           

          在Spring 的AOP中,如果一個Proxy同時實現MethodBeforeAdvice、AfterReturningAdvice和MethodInterceptor接口,那么這三個Advice的執行順序是什么樣的呢?
          經過試驗,是和xml文件中的定義順序有關的。
          如果Proxy的接口實現定義為
          ?????
          ?????????
          ??????????? MethodBeforeAdvice
          ??????????? AfterReturningAdvice
          ??????????? MethodInterceptor
          ?????????

          ?????

          那么執行的結果是
          MethodBeforeAdvice

          MethodInterceptor: before call

          Really method excuting

          MethodInterceptor: after call

          AfterReturningAdvice

          也就是說,執行順序是:MethodBeforeAdvice,MethodInterceptor的調用前的部分,目標方法,MethodInterceptor的調用后的部分,AfterReturningAdvice。

          如果proxy的定義是
          ?????
          ?????????
          ??????????? MethodBeforeAdvice
          ??????????? MethodInterceptor
          ??????????? AfterReturningAdvice
          ?????????

          ?????

          執行的結果是
          MethodBeforeAdvice

          MethodInterceptor: before call

          Really method excuting

          AfterReturningAdvice

          MethodInterceptor: after call
          也就是說,執行的順序是:MethodBeforeAdvice,MethodInterceptor的調用前的部分,目標方法,AfterReturningAdvice,MethodInterceptor的調用后的部分。

          如果proxy的定義是
          ?????
          ?????????
          ??????????? MethodInterceptor
          ??????????? MethodBeforeAdvice
          ??????????? AfterReturningAdvice
          ?????????

          ?????

          執行的結果是:
          MethodInterceptor: before call

          MethodBeforeAdvice

          Really method excuting

          AfterReturningAdvice

          MethodInterceptor: after call
          也就是說,執行的順序是:MethodInterceptor的調用前的部分,MethodBeforeAdvice,目標方法,AfterReturningAdvice,MethodInterceptor的調用后的部分。
          以上的順序是在springframework 1.2.5中測試的。

          posted on 2005-11-02 18:10 afrag 閱讀(3721) 評論(1)  編輯  收藏 所屬分類: Java隨想
          評論:
          • # re: Spring AOP中MethodBeforeAdvice、AfterReturningAdvice和MethodInterceptor的執行順序  jadmin Posted @ 2009-08-29 00:33
            是這樣的嗎?  回復  更多評論   

           
          Copyright © afrag Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 宝应县| 青河县| 巴林左旗| 贡觉县| 嵊泗县| 娄烦县| 五寨县| 文昌市| 同德县| 乌苏市| 远安县| 平塘县| 麦盖提县| 德昌县| 馆陶县| 七台河市| 江门市| 钟祥市| 伊川县| 茶陵县| 安丘市| 罗源县| 永修县| 双江| 鲁甸县| 安仁县| 花莲县| 南澳县| 孙吴县| 沐川县| 长岭县| 砚山县| 聊城市| 库尔勒市| 台山市| 蓬溪县| 施秉县| 深泽县| 泉州市| 上饶县| 揭阳市|