等待花开的季节
cmjerry · 2008-02-28
<< Spring的IntroductionInterceptor
|
首 页
|
Spring的自动代理 >>
Spring的IntroductionInterceptor(2)
2008-02-28
Tag:
Spring
introduction
advice
版权声明
:转载时请以超链接形式标明文章原始出处和作者信息及
本声明
http://cmjerry.blogbus.com/logs/16093656.html
1.Spring implements introductions through a special subinterface of Method-
Interceptor: IntroductionMethodInterceptor. This interface adds one additional
method:
boolean implementsInterface (Class intf);
This method is critical to how introduction works. implementsInterface returns
true if the IntroductionMethodInterceptor is responsible for implementing the
given interface. This means that any invocation of a method that is declared by
this interface will be delegated to the invoke() method of the Introduction-
MethodInterceptor. The invoke() method is now responsible for implementing
this method—it cannot call MethodInvocation.proceed(). It is introducing the
new interface; proceeding to the target object doesn’t make sense.
其实我们可以这么理解,我们在实现真正业务逻辑的类上加上一个拦截器,以前的拦截器都是说明业务逻辑类的方法执行前后需要加入的切面。现在我们在实现业务逻辑类上加上一个ntroductionInterceptor的拦截器,它的作用是为业务逻辑类增加新的功能方法。业务逻辑类和拦截器类的方法调用之前都必须先执行invoke方法。在这个invoke方法里,我们需要判断哪些是业务逻辑类的原来的方法,那些事业务逻辑类新增加的方法。注意新增加的方法和拦截器属于同一个类。也就是说,现在我们真正的业务逻辑类配置了拦截器后,相当于多实现了一个接口,多增加了一些方法。
/**if语句是判断是不是新增加的方法,新增加的方法属于新的接口 **/
if(implementsInterface(invocation.getMethod().getDeclaringClass()))
{
return invocation.getMethod().invoke(this, invocation.getArguments());
}
/**如果是原来的业务逻辑代码,则直接调用**/
return invocation.proceed();
随机文章:
Spring Remoting HttpInvoker产生异常的解决办法
2008-02-29
Spring Remoting(1)
2008-02-29
Spring的IntroductionInterceptor
2008-02-27
Spring的切入点Pointcut和Advisor学习
2008-02-27
JDK动态代理(Spring AOP理解的基础)
2008-02-26
收藏到:
Del.icio.us
引用地址:
cmjerry
发表于
09:57:31
|
编辑
|
继续话题
|
转发
|
推荐
发表评论
原始快照:web.archive.org