Spring AOP阅读理解--原理篇

之前是找了各种AOP的博文看了好多,现在上官网啃啃英文文档(终究是躲不过的),把关键的记录下来做笔记。
https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#spring-core

##5.8. Proxying Mechanisms机制
Spring AOP uses either JDK dynamic proxies or CGLIB to create the proxy for a given target object. JDK dynamic proxies are built into the JDK, whereas CGLIB is a common open-source class definition library (repackaged into spring-core).

If the target object to be proxied implements at least one interface, a JDK dynamic proxy is used. All of the interfaces implemented by the target type are proxied. If the target object does not implement any interfaces, a CGLIB proxy is created.

JDK 的动态代理要求代理者必须实现接口 , 否则不能生成代理对象

If you want to force the use of CGLIB proxying (for example, to proxy every method defined for the target object, not only those implemented by its interfaces), you can do so. However, you should consider the following issues:

With CGLIB, final methods cannot be advised, as they cannot be overridden in runtime-generated subclasses.
由于cglib会继承被代理类,需要重写被代理方法,所以被代理类不能是final类,被代理方法不能是final
As of Spring 4.0, the constructor of your proxied object is NOT called twice anymore, since the CGLIB proxy instance is created through Objenesis. Only if your JVM does not allow for constructor bypassing, you might see double invocations and corresponding debug log entries from Spring’s AOP support.

JDK动态代理和Cglib代理,Cglib代理可以配置强制使用的,方法是:
To force the use of CGLIB proxies, set the value of the proxy-target-class attribute of the aop:config element to true, as follows:知道可以配置就行了,如果忘记了配置细节,上官网查。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值