spring aop 中对于methodInterceptor methodBeforeAdvice methodAfterAdvice的处理过程
使用spring aop中的人都知道,定义面时,要实现methodInterceptor methodBeforeAdvice methodAfterAdvice等的接口,但详细了解后发现,这几个接口的父接口都不一样,那他是怎么处理的呢?
其实,他是将methodBforeAdvice methodAfterAdvice等几个接口的实现类也通过适配器,转换成了methodInterceptor的实现类,最后才一块运行的,
methodInterceptor接口有一个必须实现的的方法是:public Object invoke(MethodInvocation mi) throws Throwable;下面我们来看看MethodBeforeAdviceAdapter创建的MethodBeforeAdviceInterceptor的源代码:
public class MethodBeforeAdviceInterceptor implements MethodInterceptor, Serializable {
private MethodBeforeAdvice advice;
public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) {
Assert.notNull(advice, "Advice must not be null");
this.advice = advice;
}
public Object invoke(MethodInvocation mi) throws Throwable {
this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis() );
return mi.proceed();
}
}
如果你还不明白,看看http://www.iteye.com/wiki/hzbook/2262-Spring吧。