1. 程式人生 > >spring---aop(3)---Spring AOP的攔截器鏈

spring---aop(3)---Spring AOP的攔截器鏈

ati handler 攔截器 odi hand zab chain 記載 封裝

寫在前面

  時間斷斷續續,這次寫一點關於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的攔截器鏈