AopProxy源码分析

master
linlei 2024-04-23 15:48:10 +08:00
parent 431ca04c08
commit 6a62d8ea2d
1 changed files with 34 additions and 18 deletions

View File

@ -211,17 +211,26 @@ JdkDynamicAopProxy->>JdkDynamicAopProxy:this.proxiedInterfaces
JdkDynamicAopProxy->>AopProxyDemo:返回aopProxy JdkDynamicAopProxy->>AopProxyDemo:返回aopProxy
AopProxyDemo->>JdkDynamicAopProxy:aopProxy.getProxy() AopProxyDemo->>JdkDynamicAopProxy:aopProxy.getProxy()
JdkDynamicAopProxy->>JdkDynamicAopProxy:getProxy(classLoader) JdkDynamicAopProxy->>JdkDynamicAopProxy:getProxy(classLoader)
JdkDynamicAopProxy->>Proxy:Proxy.newProxyInstance()
JdkDynamicAopProxy->>AopProxyDemo:返回代理对象 JdkDynamicAopProxy->>AopProxyDemo:返回代理对象
AopProxyDemo->>$Proxy0:aopProxy.doSomething() AopProxyDemo->>$Proxy0:aopProxy.doSomething()
$Proxy0->>JdkDynamicAopProxy:invoke() $Proxy0->>JdkDynamicAopProxy:invoke()
JdkDynamicAopProxy->>ReflectiveMethodInvocation:new ReflectiveMethodInvocation() alt 不存在拦截链
ReflectiveMethodInvocation->>JdkDynamicAopProxy:返回invocation rect rgb(122,197,205)
loop 递归拦截器 JdkDynamicAopProxy->>AopUtils: invokeJoinpointUsingReflection()
JdkDynamicAopProxy->>ReflectiveMethodInvocation:invocation.proceed() AopUtils->>Method:method.invoke(target, args)
ReflectiveMethodInvocation->>ReflectiveMethodInvocation:invokeJoinpoint() Method->>$Proxy0:doSomething()
ReflectiveMethodInvocation->>AopUtils:invokeJoinpointUsingReflection() end
AopUtils->>Method:method.invoke(target, args) else 存在拦截链
Method->>$Proxy0:doSomething() rect rgb(155,205,155)
JdkDynamicAopProxy->>ReflectiveMethodInvocation:new ReflectiveMethodInvocation()
ReflectiveMethodInvocation->>JdkDynamicAopProxy:返回invocation
JdkDynamicAopProxy->>ReflectiveMethodInvocation:invocation.proceed()
ReflectiveMethodInvocation->>ReflectiveMethodInvocation:invokeJoinpoint()
ReflectiveMethodInvocation->>AopUtils:invokeJoinpointUsingReflection()
AopUtils->>Method:method.invoke(target, args)
Method->>$Proxy0:doSomething()
end
end end
~~~ ~~~
@ -245,16 +254,23 @@ CglibAopProxy->>Enhancer:enhancer.create()
CglibAopProxy->>AopProxyDemo:返回代理对象 CglibAopProxy->>AopProxyDemo:返回代理对象
AopProxyDemo->>MyServiceImpl$$EnhancerBySpringCGLIB$$:aopProxy.doSomething() AopProxyDemo->>MyServiceImpl$$EnhancerBySpringCGLIB$$:aopProxy.doSomething()
MyServiceImpl$$EnhancerBySpringCGLIB$$->>DynamicAdvisedInterceptor:intercept() MyServiceImpl$$EnhancerBySpringCGLIB$$->>DynamicAdvisedInterceptor:intercept()
DynamicAdvisedInterceptor->>CglibMethodInvocation:new CglibMethodInvocation() alt 不存在拦截链
MethodProxy->>CglibMethodInvocation:传递methodProxy rect rgb(122,197,205)
CglibMethodInvocation->>CglibMethodInvocation:接收methodProxy DynamicAdvisedInterceptor->>MethodProxy:this.methodProxy.invoke()
CglibMethodInvocation->>DynamicAdvisedInterceptor:返回invocation MethodProxy->>MyServiceImpl$$EnhancerBySpringCGLIB$$:doSomething()
DynamicAdvisedInterceptor->>CglibMethodInvocation:invocation.proceed() end
loop 递归拦截器 else 存在拦截链
CglibMethodInvocation->>ReflectiveMethodInvocation:super.proceed() rect rgb(155,205,155)
ReflectiveMethodInvocation->>CglibMethodInvocation:invokeJoinpoint() DynamicAdvisedInterceptor->>CglibMethodInvocation:new CglibMethodInvocation()
CglibMethodInvocation->>MethodProxy:this.methodProxy.invoke() MethodProxy->>CglibMethodInvocation:传递methodProxy
MethodProxy->>MyServiceImpl$$EnhancerBySpringCGLIB$$:doSomething() CglibMethodInvocation->>CglibMethodInvocation:接收methodProxy
CglibMethodInvocation->>DynamicAdvisedInterceptor:返回invocation
DynamicAdvisedInterceptor->>CglibMethodInvocation:invocation.proceed()
CglibMethodInvocation->>ReflectiveMethodInvocation:super.proceed()
ReflectiveMethodInvocation->>CglibMethodInvocation:invokeJoinpoint()
CglibMethodInvocation->>MethodProxy:this.methodProxy.invoke()
MethodProxy->>MyServiceImpl$$EnhancerBySpringCGLIB$$:doSomething()
end
end end
~~~ ~~~