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,18 +211,27 @@ 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()
alt 不存在拦截链
rect rgb(122,197,205)
JdkDynamicAopProxy->>AopUtils: invokeJoinpointUsingReflection()
AopUtils->>Method:method.invoke(target, args)
Method->>$Proxy0:doSomething()
end
else 存在拦截链
rect rgb(155,205,155)
JdkDynamicAopProxy->>ReflectiveMethodInvocation:new ReflectiveMethodInvocation() JdkDynamicAopProxy->>ReflectiveMethodInvocation:new ReflectiveMethodInvocation()
ReflectiveMethodInvocation->>JdkDynamicAopProxy:返回invocation ReflectiveMethodInvocation->>JdkDynamicAopProxy:返回invocation
loop 递归拦截器
JdkDynamicAopProxy->>ReflectiveMethodInvocation:invocation.proceed() JdkDynamicAopProxy->>ReflectiveMethodInvocation:invocation.proceed()
ReflectiveMethodInvocation->>ReflectiveMethodInvocation:invokeJoinpoint() ReflectiveMethodInvocation->>ReflectiveMethodInvocation:invokeJoinpoint()
ReflectiveMethodInvocation->>AopUtils:invokeJoinpointUsingReflection() ReflectiveMethodInvocation->>AopUtils:invokeJoinpointUsingReflection()
AopUtils->>Method:method.invoke(target, args) AopUtils->>Method:method.invoke(target, args)
Method->>$Proxy0:doSomething() Method->>$Proxy0:doSomething()
end end
end
~~~ ~~~
@ -245,17 +254,24 @@ 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()
alt 不存在拦截链
rect rgb(122,197,205)
DynamicAdvisedInterceptor->>MethodProxy:this.methodProxy.invoke()
MethodProxy->>MyServiceImpl$$EnhancerBySpringCGLIB$$:doSomething()
end
else 存在拦截链
rect rgb(155,205,155)
DynamicAdvisedInterceptor->>CglibMethodInvocation:new CglibMethodInvocation() DynamicAdvisedInterceptor->>CglibMethodInvocation:new CglibMethodInvocation()
MethodProxy->>CglibMethodInvocation:传递methodProxy MethodProxy->>CglibMethodInvocation:传递methodProxy
CglibMethodInvocation->>CglibMethodInvocation:接收methodProxy CglibMethodInvocation->>CglibMethodInvocation:接收methodProxy
CglibMethodInvocation->>DynamicAdvisedInterceptor:返回invocation CglibMethodInvocation->>DynamicAdvisedInterceptor:返回invocation
DynamicAdvisedInterceptor->>CglibMethodInvocation:invocation.proceed() DynamicAdvisedInterceptor->>CglibMethodInvocation:invocation.proceed()
loop 递归拦截器
CglibMethodInvocation->>ReflectiveMethodInvocation:super.proceed() CglibMethodInvocation->>ReflectiveMethodInvocation:super.proceed()
ReflectiveMethodInvocation->>CglibMethodInvocation:invokeJoinpoint() ReflectiveMethodInvocation->>CglibMethodInvocation:invokeJoinpoint()
CglibMethodInvocation->>MethodProxy:this.methodProxy.invoke() CglibMethodInvocation->>MethodProxy:this.methodProxy.invoke()
MethodProxy->>MyServiceImpl$$EnhancerBySpringCGLIB$$:doSomething() MethodProxy->>MyServiceImpl$$EnhancerBySpringCGLIB$$:doSomething()
end end
end
~~~ ~~~
### 七、源码分析 ### 七、源码分析