本文主要是介绍Spring 创建 JDK- and CGLIB-based proxies的区别,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
几条原则:
- If the class of a target object that is to be proxied (hereafter simply referred to as the target class) doesn't implement any interfaces, then a CGLIB-based proxy will be created.【原因是:This is the easiest scenario, because JDK proxies are interface based, and no interfaces means JDK proxying isn't even possible. 】
- If the
proxyTargetClass
property of theProxyFactoryBean
has been set totrue
, then a CGLIB-based proxy will be created. 【无视ProxyFactoryBean的属性proxyInterfaces是否有设置成为某一个或多个接口名
】 - If the
proxyInterfaces
property of theProxyFactoryBean
has been set to one or more fully qualified interface names, then a JDK-based proxy will be created.
- If the
proxyInterfaces
property of theProxyFactoryBean
has not been set but the target class does implement one (or more) interfaces, then theProxyFactoryBean
will auto-detect the fact that the target class does actually implement at least one interface, and a JDK-based proxy will be created, or a CGLIB-based proxy will be created.【如果是JDK代理这一条和第三条行为一致】
这篇关于Spring 创建 JDK- and CGLIB-based proxies的区别的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!