Java?????spring AOP ??????
???????????? ???????[ 2015/5/4 13:39:50 ] ???????????????
????????????????????????????????????????????Interceptor Chain????????У???????????????joinpoint; ?????У????????????joinpoint?????????????????????λ??????????????????е????????????????
????????????????????????????????????Advised.getInterceptorsAndDynamicInterceptionAdvice()?????????????????????????????????????:
????public List<Object>getInterceptorsAndDynamicInterceptionAdvice(Method method?? Class targetClass) {
????MethodCacheKeycacheKey = new MethodCacheKey(method);
????List<Object>cached = this.methodCache.get(cacheKey);
????if(cached == null) {
????cached= this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(
????this??method?? targetClass);
????this.methodCache.put(cacheKey??cached);
????}
????returncached;
????}
????????????????????????????AdvisorChainFactory. getInterceptorsAndDynamicInterceptionAdvice()????????????????????????????檔
?????????????????????????????
/**
* ?????????????config?л??advisor?б????????????Щadvisor.?????IntroductionAdvisor??
* ???ж??Advisor????????????targetClass??.?????PointcutAdvisor?????ж?
* ??Advisor????????????method??.????????????Advisor???AdvisorAdaptor?????Interceptor?б????.
*/
publicList getInterceptorsAndDynamicInterceptionAdvice(Advised config?? Methodmethod?? Class targetClass) {
// This is somewhat tricky... we have to process introductions first??
// but we need to preserve order in the ultimate list.
List interceptorList = new ArrayList(config.getAdvisors().length);
//????????IntroductionAdvisor
boolean hasIntroductions = hasMatchingIntroductions(config??targetClass);
//????????????????AdvisorAdapter???????Advisor?????MethodInterceptor
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance();
Advisor[] advisors = config.getAdvisors();
for (int i = 0; i <advisors.length; i++) {
Advisor advisor = advisors[i];
if (advisor instanceof PointcutAdvisor) {
// Add it conditionally.
PointcutAdvisor pointcutAdvisor= (PointcutAdvisor) advisor;
if(config.isPreFiltered() ||pointcutAdvisor.getPointcut().getClassFilter().matches(targetClass)) {
//TODO: ??????????????????λ??????????
//??Advisor?????Interceptor
MethodInterceptor[]interceptors = registry.getInterceptors(advisor);
//??鵱?advisor??pointcut??????????????
MethodMatcher mm =pointcutAdvisor.getPointcut().getMethodMatcher();
if (MethodMatchers.matches(mm??method?? targetClass?? hasIntroductions)) {
if(mm.isRuntime()) {
// Creating a newobject instance in the getInterceptors() method
// isn't a problemas we normally cache created chains.
for (intj = 0; j < interceptors.length; j++) {
interceptorList.add(new InterceptorAndDynamicMethodMatcher(interceptors[j]??mm));
}
} else {
interceptorList.addAll(Arrays.asList(interceptors));
}
}
}
} else if (advisor instanceof IntroductionAdvisor){
IntroductionAdvisor ia =(IntroductionAdvisor) advisor;
if(config.isPreFiltered() || ia.getClassFilter().matches(targetClass)) {
Interceptor[] interceptors= registry.getInterceptors(advisor);
interceptorList.addAll(Arrays.asList(interceptors));
}
} else {
Interceptor[] interceptors =registry.getInterceptors(advisor);
interceptorList.addAll(Arrays.asList(interceptors));
}
}
return interceptorList;
}
??????????????????Advised???????????????????????????Advisor????????????MethodInterceptor.
??????????????????μ????????????????????????
????if (chain.isEmpty()) {
????retVal = AopUtils.invokeJoinpointUsingReflection(target??method?? args);
????} else {
????//????MethodInvocation
????invocation = newReflectiveMethodInvocation(proxy?? target?? method?? args?? targetClass?? chain);
????retVal = invocation.proceed();
????}
????????δ???????????????????????????????????????????????????????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);
}
}
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Java???????????Щ???????????????Java????????????????Java?б???Map????????Java Web???????????????Java??????????????д?????Java????????7???????????????????????(java .net ?????)???Java??????????Python??????Java webdriver??λ????????′????е?????Java??д??????????????????Java???????????????JavaScript????????????Java?????????????????? Java???????10??????????????Java?м????????????????java???????ü???????????м???????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????