cglib动态代理浅析
cglib Proxy 实现原理(CglibAopProxy#getProxy)
- 获取该类的拦截器 Callback[] callbacks = getCallbacks(rootClass);
1.1 切面相关的拦截器:DynamicAdvisedInterceptor - 切面拦截器:DynamicAdvisedInterceptor#intercept
2.1 interceptorsAndDynamicMethodMatchers属性初始化
2.2 interceptorsAndDynamicMethodMatchers属性初始化(判断方法是否进拦截器的关系属性)
2.3 AspectJExpressionPointcut#matches(对方法进行过滤匹配)AspectJExpressionPointcut的调用栈 List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, targetClass); -->DefaultAdvisorChainFactory#getInterceptorsAndDynamicInterceptionAdvice -->match = ((IntroductionAwareMethodMatcher) mm).matches(method, actualClass, hasIntroductions);
创建ShadowMatch AspectJExpressionPointcut#getShadowMatch -->PointcutExpressionImpl#matchesMethodExecution -->ShadowMatchImpl sm = this.getShadowMatch(s); 1. FuzzyBoolean match = this.pointcut.match(forShadow);(详细分析见:https://blog.csdn.net/quyixiao/article/details/109343482) -->Pointcut#match -->ret = this.matchInternal(shadow);//KindedPointcut#matchInternal -->-->SignaturePattern#matches 1.1 JoinPointSignatureIterator candidateMatches = joinPointSignature.getJoinPointSignatures(world); -->candidateMatches包含接口或者父类中的方法 1.2 do..while循环匹配(如果都匹配不上返回false) -->SignaturePattern#matchesExactlyMethod --> this.declaringType.matchesStatically(aMethod.getDeclaringType().resolve(world))//WildTypePattern#matchesExactly (1)如果包名和类名匹配不是*,则对第一项进行匹配 (2) 如果表达式方法参数类型只有一个参数,并且是 .. ,则直接返回 YES
- 代理拦截方法:ReflectiveMethodInvocation#proceed
```
if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) {
}return invokeJoinpoint();
- interceptorsAndDynamicMethodMatchers(见上面分析)拦截器调完后,调用自己本身 ```
相关文章
- 基于-SLF4J-MDC-机制的日志链路追踪配置属性
ums: # ================ 基于 SLF4J MDC 机制的日志链路追踪配置属性 ================ mdc: # 是否支持基于 SLF4J MDC
- ajax-跨域访问
ajax 跨域访问 <!DOCTYPE html> <html xmlns:th="http://www.w3.org/1999/xhtml"> <head>
- 给第三方登录时用的数据库表-user_connection-与-auth_token-添加-redis-cache
spring: # 设置缓存为 Redis cache: type: redis # redis redis: host: 192.168.88.88 port
- Java动态代理
Jdk动态代理 通过InvocationHandler和Proxy针对实现了接口的类进行动态代理,即必须有相应的接口 应用 public class TestProxy { public
- Java读取classpath中的文件
public void init() { try { //URL url = Thread.currentThread().getContextClassLo
随机推荐
- 基于-SLF4J-MDC-机制的日志链路追踪配置属性
ums: # ================ 基于 SLF4J MDC 机制的日志链路追踪配置属性 ================ mdc: # 是否支持基于 SLF4J MDC
- ajax-跨域访问
ajax 跨域访问 <!DOCTYPE html> <html xmlns:th="http://www.w3.org/1999/xhtml"> <head>
- 给第三方登录时用的数据库表-user_connection-与-auth_token-添加-redis-cache
spring: # 设置缓存为 Redis cache: type: redis # redis redis: host: 192.168.88.88 port
- Java动态代理
Jdk动态代理 通过InvocationHandler和Proxy针对实现了接口的类进行动态代理,即必须有相应的接口 应用 public class TestProxy { public
- Java读取classpath中的文件
public void init() { try { //URL url = Thread.currentThread().getContextClassLo