從這段代碼可以看出,如果得到的攔截器鏈為空,則直接反射調(diào)用目標(biāo)方法,否則創(chuàng)建MethodInvocation,調(diào)用其proceed方法,觸發(fā)攔截器鏈的執(zhí)行,來看下具體代碼
public?Object?proceed()?throws?Throwable?{??
//??We?start?with?an?index?of?-1and?increment?early.??
if?(this.currentInterceptorIndex?==?this.interceptorsAndDynamicMethodMatchers.size()-?1)?{??
//如果Interceptor執(zhí)行完了,則執(zhí)行joinPoint??
return?invokeJoinpoint();??
}??
Object?interceptorOrInterceptionAdvice?=??
this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex);??
//如果要?jiǎng)討B(tài)匹配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;??
//動(dòng)態(tài)匹配:運(yùn)行時(shí)參數(shù)是否滿足匹配條件??
if?(dm.methodMatcher.matches(this.method,?this.targetClass,this.arguments))?{??
//執(zhí)行當(dāng)前Intercetpor??
returndm.interceptor.invoke(this);??
}??
else?{??
//動(dòng)態(tài)匹配失敗時(shí),略過當(dāng)前Intercetpor,調(diào)用下一個(gè)Interceptor??
return?proceed();??
}??
}??
else?{??
//?It's?an?interceptor,?so?we?just?invoke?it:?The?pointcutwill?have??
//?been?evaluated?statically?before?this?object?was?constructed.??
//執(zhí)行當(dāng)前Intercetpor??
return?((MethodInterceptor)?interceptorOrInterceptionAdvice).invoke(this);??
}??
} ?
評論
查看更多