【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
来源:互联网 发布:c语言把字符a变成字符b 编辑:程序博客网 时间:2024/06/15 14:28
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>
而如果使用@AspectJ风格使用如下方式来指定使用CGLIB代理:
java代码:
- <aop:aspectj-autoproxy proxy-target-class="true"/>
0 0
- 【第六章】 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
- MKMapView 缩放等级 原理详解
- foreach遍历的实质
- ios开发的建议学习
- C Primer Plus4-1
- HashMap解决hash冲突的方法
- 【第六章】 AOP 之 6.9 代理机制 ——跟我学spring3
- python如何实现callback
- Java把Html格式文本转换成纯文本的问题
- 2016年新计划
- C Primer Plus4-2
- 尝试《Java Network Programming 4ed》的部分翻译
- 刨根问底Objective-C Runtime(唐巧)
- oracle数据库相关
- C Primer Plus4-3