tomcat源码分析3—>cglib动态代理深度解析

来源:互联网 发布:lego ev3编程软件下载 编辑:程序博客网 时间:2024/06/16 12:21

通过对cglib的核心类enhancer的分析,该类库实现动态代理的方式是:
Enhancer.java

....../**     * Set the class which the generated class will extend. As a convenience,     * if the supplied superclass is actually an interface, <code>setInterfaces</code>     * will be called with the appropriate argument instead.     * A non-interface argument must not be declared as final, and must have an     * accessible constructor.     * @param superclass class to extend or interface to implement     * @see #setInterfaces(Class[])     */    public void setSuperclass(Class superclass) {        if (superclass != null && superclass.isInterface()) {            setInterfaces(new Class[]{ superclass });        } else if (superclass != null && superclass.equals(Object.class)) {            // affects choice of ClassLoader            this.superclass = null;        } else {            this.superclass = superclass;        }    }......

通过该方法的注释,我们可以看出cglib其实是通过生成新的类来实现代理的:
1、初始化方法拦截器MethodInterceptor。
2、根据继承(类:extends,接口:implements)传人的被代理类,并注册相应的方法拦截器为callback。

通过上面两步骤就可以实现代理了

总结:还没有把源码都看一遍,所以还有部分细节需要求证。

阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 中层干部管理培训 仓库系统管理软件 危险化学品管理 中高层管理培训 企业管理人员 品质管理制度 公司出差管理制度 生产运营管理 生产安全管理培训 什么是管理体系 企业供应链管理 智能化仓库管理系统 什么是质量管理体系 建筑质量管理体系 经济管理专业学什么 团队管理软件 企业管理软件 什么是管理信息系统 品质质量管理 数据库管理软件 管理公司经营范围 项目全过程管理 企业知识库管理系统 企业营销管理培训 人员管理办法 企业管理信息化 智慧校园管理系统 产品质量管理系统 技术管理制度 生产管理方法 公司财务管理制度 公共管理类有哪些专业 科研项目管理系统 供应商质量管理 9001质量管理体系认证 销售团队管理 什么是质量管理 工程质量管理体系 安全管理人员考试 生产安全管理 资料管理系统