【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
来源:互联网 发布:淘宝新开的店铺发货慢 编辑:程序博客网 时间:2024/06/07 14:46
Spring AOP通过代理模式实现,目前支持两种代理:JDK动态代理、CGLIB代理来创建AOP代理,Spring建议优先使用JDK动态代理。
- JDK动态代理:使用java.lang.reflect.Proxy动态代理实现,即提取目标对象的接口,然后对接口创建AOP代理。
- CGLIB代理:CGLIB代理不仅能进行接口代理,也能进行类代理,CGLIB代理需要注意以下问题:
不能通知final方法,因为final方法不能被覆盖(CGLIB通过生成子类来创建代理)。
会产生两次构造器调用,第一次是目标类的构造器调用,第二次是CGLIB生成的代理类的构造器调用。如果需要CGLIB代理方法,请确保两次构造器调用不影响应用。
Spring AOP默认首先使用JDK动态代理来代理目标对象,如果目标对象没有实现任何接口将使用CGLIB代理,如果需要强制使用CGLIB代理,请使用如下方式指定:
对于Schema风格配置切面使用如下方式来指定使用CGLIB代理:
java代码:
- <aop:config proxy-target-class="true">
- </aop:config>
<aop:config proxy-target-class="true"></aop:config>
而如果使用@AspectJ风格使用如下方式来指定使用CGLIB代理:
java代码:
- <aop:aspectj-autoproxy proxy-target-class="true"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- 【第六章】 AOP 之 6.1 AOP基础 ——跟我学spring3
- 【第六章】 AOP 之 6.2 AOP的HelloWorld ——跟我学spring3
- 【第六章】 AOP 之 6.3 基于Schema的AOP ——跟我学spring3
- 【第六章】 AOP 之 6.4 基于@AspectJ的AOP ——跟我学spring3
- 【第六章】 AOP 之 6.1 AOP基础 ——跟我学spring3
- 【第六章】 AOP 之 6.2 AOP的HelloWorld ——跟我学spring3
- 【第六章】 AOP 之 6.3 基于Schema的AOP ——跟我学spring3
- 【第六章】 AOP 之 6.4 基于@AspectJ的AOP ——跟我学spring3
- 【第六章】 AOP 之 6.1 AOP基础 ——跟我学spring3
- 【第六章】 AOP 之 6.2 AOP的HelloWorld ——跟我学spring3
- 黑马程序员----【javaSE基础】入门基础--数据类型及转换
- 【第六章】 AOP 之 6.7 通知顺序 ——跟我学spring3
- 【第六章】 AOP 之 6.8 切面实例化模型 ——跟我学spring3
- 安卓中的四大组件_Service
- 将 VMware 最小化到系统托盘
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- 【第七章】 对JDBC的支持 之 7.1 概述 ——跟我学spring3
- 成都国际非物质文化遗产博览园
- 【Linux基础】消息队列应用
- java面试题01
- 安卓中的四大组件_ContentProvider
- 【Linux基础】信号量基本操作
- plsa代码实现
- C#中获得月份中的第一天和最后一天和判断闰年