What is CGLIB and how it is related to Spring? Do we have to define usage of CGLIB explicitly when using Spring Framework?
Ref Spring docs. What is CGLIB & how is it related to Spring?
CGLIB is a code generation 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.
Via 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.
Via 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.