Spring Aop源码学习--Aop代理工厂AopProxyFactory
来源:互联网 发布:淘宝店铺怎样加粉丝 编辑:程序博客网 时间:2024/05/22 11:38
Spring AOP提供了Aop代理类的工厂类AopProxyFactory,其作用就是创建AopProxy类。
//Aop工厂,创建AOPpublic interface AopProxyFactory {//创建AOPAopProxy createAopProxy(AdvisedSupport config) throws AopConfigException;}
AopProxyFactory会创建两种代理类:
(1)jdk提供接口实现的JdkDynamicAopProxy
(2)cglib提供接口实现的ObjenesisCglibAopProxy
在Spring配置文件中配置<aop:aspectj-autoproxy proxy-target-class="true"/>时会默认创建ObjenesisCglibAopProxy,如果没有配置的话就需要根据被代理类是否有接口来选择判断了,如果被代理类由接口则选择使用JdkDynamicAopProxy,否则使用ObjenesisCglibAopProxy,这样选择的原因是由于jdk和cglib实现代理的机制不同来决定的。
@SuppressWarnings("serial")public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {//Spring提供了两种代理类创建方式jdk动态代理和cglib动态代理@Overridepublic AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {//AopProxy创建是根据目标类是否有接口if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) {Class<?> targetClass = config.getTargetClass();if (targetClass == null) {throw new AopConfigException("TargetSource cannot determine target class: " +"Either an interface or a target is required for proxy creation.");}if (targetClass.isInterface() || Proxy.isProxyClass(targetClass)) {return new JdkDynamicAopProxy(config);}return new ObjenesisCglibAopProxy(config);}else {return new JdkDynamicAopProxy(config);}}private boolean hasNoUserSuppliedProxyInterfaces(AdvisedSupport config) {Class<?>[] ifcs = config.getProxiedInterfaces();return (ifcs.length == 0 || (ifcs.length == 1 && SpringProxy.class.isAssignableFrom(ifcs[0])));}}
阅读全文
0 0
- Spring Aop源码学习--Aop代理工厂AopProxyFactory
- Spring Aop源码学习--Aop代理AopProxy
- Spring学习,AOP底层代理
- Spring源码学习之AOP
- Spring源码之创建AOP代理
- Spring源码之 AOP 代理流程
- spring 源码探索-- 静态AOP代理
- spring源码-5-aop动态代理
- Spring学习总结2(AOP-代理模式)
- Spring AOP代理的学习案例
- Spring AOP 学习之静态代理
- Spring AOP 学习之cJlib动态代理
- Spring学习历程 --- AOP基础之代理
- Spring学习笔记:使用代理实现AOP
- spring aop学习5:jdk静态代理
- Spring AOP 代理机制
- spring aop代理列子
- Spring Aop xml代理
- 转载{shader流光效果}
- KVM硬件辅助虚拟化之 EPT(Extended Page Table)
- python字符串——"奇葩“的内置函数
- css3新特性
- 线程安全和可重入函数
- Spring Aop源码学习--Aop代理工厂AopProxyFactory
- JavaScript与用户互动
- Intellij 打开就闪退或关闭
- react native 调用原生UI组件
- Codeforces
- IOC的理解
- dagger2理解分享_实现解耦
- python3 [爬虫入门实战]爬虫之mongoDB数据库的安装配置与可视化
- stamen的程序员之路