Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

指定了(proxy-target-classs设为true)一定使用Cglib吗? #9

Open
wuqinduo opened this issue Nov 13, 2019 · 1 comment
Open

Comments

@wuqinduo
Copy link

@OverRide
public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {
if (config.isOptimize() || config.isProxyTargetClass() ||
hasNoUserSuppliedProxyInterfaces(config)) {
Class<?> targetClass = config.getTargetClass();
if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) {
return new JdkDynamicAopProxy(config);
}
return new ObjenesisCglibAopProxy(config);
} else {
return new JdkDynamicAopProxy(config);
}
}
逻辑很明显,如果指定了(proxy-target-classs设为true)使用Cglib,那么就会使用Cglib的方式,如果没有指定(或为false),那么先回检测被代理类是否实现了自己的接口,如果实现了,那么就采用JDK动态代理的方式。


在设置(proxy-target-classs设为true)的情况下走
if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) {
return new JdkDynamicAopProxy(config);
}
不是也可能使用JDK吗?我不太理解这个地方。 为啥都说(proxy-target-classs设为true使用CGLB代理呢?

@Naughty-Star
Copy link

设置了proxy-target-classs 为true,也会判断是否是接口类和代理类,CGLIB是用继承的方式实现的,不支持这两种方式的类做代理,或许可以优化下这段代码,让读者更清晰一点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants