從這段代碼可以看出,如果得到的攔截器鏈為空,則直接反射調用目標方法,否則創建MethodInvocation,調用其proceed方法,觸發攔截器鏈的執行,來看下具體代碼
public?Object?proceed()?throws?Throwable?{??
//??We?start?with?an?index?of?-1and?increment?early.??
if?(this.currentInterceptorIndex?==?this.interceptorsAndDynamicMethodMatchers.size()-?1)?{??
//如果Interceptor執行完了,則執行joinPoint??
return?invokeJoinpoint();??
}??
Object?interceptorOrInterceptionAdvice?=??
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex);??
//如果要動態匹配joinPoint??
if?(interceptorOrInterceptionAdvice?instanceof?InterceptorAndDynamicMethodMatcher){??
//?Evaluate?dynamic?method?matcher?here:?static?part?will?already?have??
//?been?evaluated?and?found?to?match.??
InterceptorAndDynamicMethodMatcher?dm?=??
(InterceptorAndDynamicMethodMatcher)interceptorOrInterceptionAdvice;??
//動態匹配:運行時參數是否滿足匹配條件??
if?(dm.methodMatcher.matches(this.method,?this.targetClass,this.arguments))?{??
//執行當前Intercetpor??
returndm.interceptor.invoke(this);??
}??
else?{??
//動態匹配失敗時,略過當前Intercetpor,調用下一個Interceptor??
return?proceed();??
}??
}??
else?{??
//?It's?an?interceptor,?so?we?just?invoke?it:?The?pointcutwill?have??
//?been?evaluated?statically?before?this?object?was?constructed.??
//執行當前Intercetpor??
return?((MethodInterceptor)?interceptorOrInterceptionAdvice).invoke(this);??
}??
} ?
評論
查看更多