jinfeng_wang

G-G-S,D-D-U!

BlogJava 首页 新随笔 联系 聚合 管理
  400 Posts :: 0 Stories :: 296 Comments :: 0 Trackbacks

 

1、  around advice:所有around advice必须实现MethodInterceptor接口,注意invoke方法的参数invocationMethodInvocation接口,在此中包含了许多信息,包括其所封装的方法及其参数,AOP proxyJointcut等。

public interface MethodInterceptor extends Interceptor {

                  Object invoke(MethodInvocation invocation) throws Throwable;

}

    在实现around advice时,和before adviceafter advice有着两个很大的区别:1、必须在invoke方法中调用MethodInvocation.proceed(),这样才能将所有调用延续下去,调用target对象的method2、必须自己返回一个object,该object甚至可以与target’s method的返回值不一样。

 

2、  before advice:在jointcut执行之前,运行advice。必须实现MethodBeforeAdvice接口。

public interface MethodBeforeAdvice extends BeforeAdvice {

    void before(Method m, Object[] args, Object target) throws Throwable;

}

3、  after advice:在jointcut执行之后,运行advice。必须实现AfterReturningAdvice接口。

public interface AfterReturningAdvice extends Advice {

    void afterReturning(Object returnValue, Method m, Object[] args, Object target)

            throws Throwable;

}

4、  throws advice:在jointcut执行出现异常的时候,运行此advice。必须实现ThrowsAdvice接口。但是此接口只是一个标识接口,必须实现此外实现下面的方法: 

afterThrowing([Method], [args], [target], subclassOfThrowable)

   此外,在jointcut出现异常时,具体调用哪个afterThrowing方法,这就涉及到类型判别,最符合类型判别的将会被调用。
posted on 2005-03-02 17:31 jinfeng_wang 阅读(1176) 评论(0)  编辑  收藏 所属分类: spring

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


网站导航: