What is CGLIB in Spring Framework? [closed]

荒凉一梦 提交于 2019-11-29 00:54:09

问题


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.



来源:https://stackoverflow.com/questions/38089200/what-is-cglib-in-spring-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!