afrag  
记录学习和成长的历程
日历
<2009年8月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345
统计
  • 随笔 - 9
  • 文章 - 5
  • 评论 - 2
  • 引用 - 0

导航

常用链接

留言簿

随笔分类

随笔档案

文章档案

搜索

  •  

积分与排名

  • 积分 - 9897
  • 排名 - 2389

最新评论

阅读排行榜

评论排行榜

 

在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 阅读(3692) 评论(1)  编辑  收藏 所属分类: Java随想
评论:
  • # re: Spring AOP中MethodBeforeAdvice、AfterReturningAdvice和MethodInterceptor的执行顺序  jadmin Posted @ 2009-08-29 00:33
    是这样的吗?  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © afrag Powered by: 博客园 模板提供:沪江博客