What is CGLIB and how it is related to Spring? Do we have to define usage of CGLIB explicitly when using Spring Framework?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Ref Spring docs. What is CGLIB & how is it related to Spring?
CGLIB is a code genration library. Spring uses CGLIB, to generate proxies.
Spring AOP defaults to using standard JDK dynamic proxies for AOP proxies. This enables any interface (or set of interfaces) to be proxied.
Yes you have to tell spring to use CGLIB based proxies explicitly.
Through xml:
<aop:aspectj-autoproxy proxy-target-class="true"/>
proxy-target-class property is set to true will cause CGLIB-based proxying to be in effect.
Through Annotation:
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class AppConfig {
// ...
}
There is no need to add CGLIB to your classpath. As of Spring 3.2, CGLIB is repackaged and included in the spring-core JAR.
You may have look at this too.