基于Spring AOP proxyTargetClass的行为表现总结
作者:安迪源文 时间:2022-05-23 18:33:43
Spring AOP proxyTargetClass的行为
要点列表形式
proxyTargetClass
true
目标对象实现了接口 – 使用CGLIB代理机制
目标对象没有接口(只有实现类) – 使用CGLIB代理机制
false
目标对象实现了接口 – 使用JDK * 机制(代理所有实现了的接口)
目标对象没有接口(只有实现类) – 使用CGLIB代理机制
表格形式
proxyTargetClass | 目标对象特征 | 代理效果 |
---|---|---|
true | 目标对象实现了接口 | 使用CGLIB代理机制 |
true | 目标对象没有接口(只有实现类) | 使用CGLIB代理机制 |
false | 目标对象实现了接口 | 使用JDK * 机制(代理所有实现了的接口) |
false | 目标对象没有接口(只有实现类) | 使用CGLIB代理机制 |
proxy-target-class="true" 与proxy-target-class="false"的区别
<tx:annotation-driven transaction-manager="transactionManager"
proxy-target-class="true"/>
注意:proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。
如果proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。
如果proxy-target-class 属值被设置为false或者这个属性被省略,那么标准的JDK 基于接口的代理将起作用。
即使你未声明 proxy-target-class="true" ,但运行类没有继承接口,spring也会自动使用CGLIB代理。
高版本spring自动根据运行类选择 JDK 或 CGLIB 代理
来源:https://andyboke.blog.csdn.net/article/details/83960798
标签:Spring,AOP,proxyTargetClass
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SpringBoot的DeferredResult案例:DeferredResult的超时处理方式
2023-08-09 14:00:58
![](https://img.aspxhome.com/file/2023/6/68226_0s.jpg)
eclipse如何搭建Springboot项目详解
2023-11-29 04:52:36
![](https://img.aspxhome.com/file/2023/7/60597_0s.png)
手动模拟JDK动态代理的方法
2023-03-23 00:49:03
spring boot学习笔记之操作ActiveMQ指南
2023-09-12 20:11:52
第三方包jintellitype实现Java设置全局热键
2023-09-25 10:33:50
java导出大批量(百万以上)数据的excel文件
2023-11-16 13:13:22
Java集合使用 Iterator 删除元素
2022-02-25 12:32:44
java实现双色球彩票游戏
2022-06-29 12:39:45
![](https://img.aspxhome.com/file/2023/2/66652_0s.jpg)
Java重写与重载之间的区别
2021-06-30 03:16:13
JAVA实现LRU算法的参考示例
2022-01-26 21:56:49
基于java ssm springboot+mybatis酒庄内部管理系统设计和实现
2023-09-24 23:51:17
![](https://img.aspxhome.com/file/2023/9/58449_0s.jpg)
JWT在OpenFeign调用中进行令牌中继详解
2023-02-07 04:19:15
Java毕业设计实战之在线网盘系统的实现
2023-03-05 05:42:47
![](https://img.aspxhome.com/file/2023/3/72523_0s.jpg)
Java与Node.js利用AES加密解密出相同结果的方法示例
2021-09-11 21:06:58
SpringBoot文件访问映射如何实现
2022-07-22 00:36:07
浅谈spring security入门
2023-02-20 04:48:58
![](https://img.aspxhome.com/file/2023/2/63782_0s.png)
kafka并发写大消息异常TimeoutException排查记录
2023-11-27 23:07:11
![](https://img.aspxhome.com/file/2023/8/60368_0s.png)
Spring component-scan XML配置与@ComponentScan注解配置
2023-07-04 03:37:12
SpringBoot 自定义starter yaml提示失效问题及解决方法
2022-08-03 14:58:42
![](https://img.aspxhome.com/file/2023/5/70945_0s.jpg)
mybatis foreach 循环 list(map)实例
2023-11-23 23:39:05
![](https://img.aspxhome.com/file/2023/6/58876_0s.jpg)