首页 > 代码库 > spring---aop(3)---Spring AOP的拦截器链

spring---aop(3)---Spring AOP的拦截器链

写在前面

  时间断断续续,这次写一点关于spring aop拦截器链的记载。至于如何获取spring的拦截器,前一篇博客已经写的很清楚(spring---aop(2)---Spring AOP的JDK动态代理)

 

获取拦截器链

final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializable {

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        ...
       //获取拦截器链   List
<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass); // Check whether we have any advice. If we don‘t, we can fallback on direct if (chain.isEmpty()) { // 如果拦截器链为空,则执行目标方法 retVal = AopUtils.invokeJoinpointUsingReflection(target, method, args); } else { // 封装拦截器链的执行方法 invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain); // 拦截器链执行 retVal = invocation.proceed(); }
     ... }

 

spring---aop(3)---Spring AOP的拦截器链