Spring-AOP、Struts2拦截器、MyBatis Plugin实现原理比较(三)
Spring AOP
?
Spring和struts2拦截链的实现理念是一样的,所有的拦截器会组织成一个链,由中央调度器统一推进。
?
Spring在拦截器(通知 Advice) 的接口上做得更细致一些,在MyBatis和Struts2中,拦截器链的推进是要在每个拦截器的实现中显式调用的。而在Spring中,这个动作已经被封装了。
?
看下面这个?AfterReturningAdvice 通知
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {MethodInvocation invocation;Object oldProxy = null;boolean setProxyContext = false;TargetSource targetSource = this.edvised.targetSource;Class targetClass = null;Object target = null;try {.......if (chain.isEmpty()) {retVal = AopUtils.invokeJoinpointUsingReflection(target, method, args);}else {// We need to create a method invocation...invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);// Proceed to the joinpoint through the interceptor chain.retVal = invocation.proceed();}.......return retVal;}finally {.......}}?
?
?