Spring AOP源码实现
2025-08-11 15:38:55 2 举报
AI智能生成
Spring AOP源码实现
作者其他创作
大纲/内容
ProxyFactoryBean#getObject
ProxyFactoryBean#initializeAdvisorChain
name.endsWith("*")
ProxyFactoryBean#addGlobalAdvisors
ProxyFactoryBean#addAdvisorOnChainCreation(advice)
prototype类型Bean的处理
PrototypePlaceholderAdvisor#PrototypePlaceholderAdvisor
singleton类型Bean的处理
advice = beanFactory.getBean(name)
ProxyFactoryBean#addAdvisorOnChainCreation(advice)
singleton生成对应的proxy
ProxyFactoryBean#getSingletonInstance
AdvisedSupport#getTargetClass
interfaces= ClassUtils#getAllInterfacesForClass(targetClass, this.proxyClassLoader))
AdvisedSupport#setInterfaces(Class<?>... interfaces)
AopProxy = ProxyCreatorSupport#createAopProxy
DefaultAopProxyFactory#createAopProxy
JdkDynamicAopProxy#JdkDynamicAopProxy
this.advised = config;
this.proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(this.advised, true);
this.proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(this.advised, true);
this.findDefinedEqualsAndHashCodeMethods(this.proxiedInterfaces);
JdkDynamicAopProxy#getProxy()
Proxy#newProxyInstance(ClassLoader, proxiedInterfaces, java.lang.reflect.InvocationHandler)
java.lang.reflect.Proxy#getProxyConstructor
java.lang.reflect.Proxy#newProxyInstance(java.lang.Class<?>, java.lang.reflect.Constructor<?>, java.lang.reflect.InvocationHandler)
java.lang.reflect.Constructor#newInstance
JdkDynamicAopProxy#invoke
HotSwappableTargetSource#getTarget
HotSwappableTargetSource#swap
AdvisedSupport#getInterceptorsAndDynamicInterceptionAdvice
DefaultAdvisorChainFactory#getInterceptorsAndDynamicInterceptionAdvice
ReflectiveMethodInvocation#ReflectiveMethodInvocation
invocation.proceed()
ReflectiveMethodInvocation#proceed
ReflectiveMethodInvocation#invokeJoinpoint
interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex)
methodMatcher.matches
interceptor.invoke
MethodBeforeAdviceInterceptor#invoke
AspectJMethodBeforeAdvice#before
AbstractAspectJAdvice#invokeAdviceMethod
AbstractAspectJAdvice#invokeAdviceMethodWithGivenArgs
java.lang.reflect.Method#invoke
ReflectiveMethodInvocation#proceed
AfterReturningAdviceInterceptor#invoke
ReflectiveMethodInvocation#proceed
AspectJAfterReturningAdvice#afterReturning
AbstractAspectJAdvice#invokeAdviceMethod
AbstractAspectJAdvice#invokeAdviceMethodWithGivenArgs
java.lang.reflect.Method#invoke
ThrowsAdviceInterceptor#invoke
try{ReflectiveMethodInvocation#proceed}catch{}
ThrowsAdviceInterceptor#invokeHandlerMethod
java.lang.reflect.Method#invoke
AopUtils#invokeJoinpointUsingReflection(this.advised, method, args)
ReflectionUtils#makeAccessible(method)
java.lang.reflect.method.invoke(target, args)
ObjenesisCglibAopProxy#ObjenesisCglibAopProxy
CglibAopProxy#CglibAopProxy
this.advised = config;
this.advisedDispatcher = new AdvisedDispatcher(this.advised);
this.advisedDispatcher = new AdvisedDispatcher(this.advised);
CglibAopProxy#getProxy(java.lang.ClassLoader)
AdvisedSupport#getTargetClass
验证代理对象的接口设置
CglibAopProxy#createEnhancer
设置Enhancer对象
CglibAopProxy#getCallbacks
DynamicAdvisedInterceptor#DynamicAdvisedInterceptor
CglibAopProxy#createProxyClassAndInstance
Enhancer#create
CglibAopProxy.DynamicAdvisedInterceptor#intercept
AdvisedSupport#getInterceptorsAndDynamicInterceptionAdvice
DefaultAdvisorChainFactory#getInterceptorsAndDynamicInterceptionAdvice
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance();
registry.getInterceptors(advisor)
Advice advice = advisor.getAdvice();
advice instanceof MethodInterceptor
AdvisorAdapter#supportsAdvice
interceptors.add(adapter.getInterceptor(advisor))
interceptorList.add(new InterceptorAndDynamicMethodMatcher(interceptor, mm))
MethodMatchers.matches
DefaultAdvisorChainFactory#hasMatchingIntroductions
CglibMethodInvocation#CglibMethodInvocation
ReflectiveMethodInvocation#ReflectiveMethodInvocation
invocation.proceed()
methodProxy.invoke(target, argsToUse)r
ProxyFactoryBean#getProxy(AopProxy)
prototype生成对应的proxy
ProxyFactoryBean#newPrototypeInstance
0 条评论
下一页