Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between Spring CGLIB and CGLIB?

Spring doesn't contains cglib dependency, both cglib and spring cglib has the Enhancer class, one is net.sf.cglib.proxy.Enhancer while the another is org.springframework.cglib.proxy, what's the difference between them?

like image 471
zyl Avatar asked Jan 05 '17 06:01

zyl


2 Answers

This is called repackaging: instead of using some library as a dependency, a project makes a copy of the dependency as part of their own project and places it in a different package.

The reason for doing this is that a project using Spring might want to use cglib itself. If Spring had a particular version of cglib as a dependency, it would be impossible for the project using Spring to pick a different version. But if Spring uses repackaged cglib which is in a different package, there is no version conflict and the project can use any version of cglib if they like.

Some projects repackage Guava, Netty or other popular libraries in a similar manner.

like image 111
Michał Kosmulski Avatar answered Oct 19 '22 19:10

Michał Kosmulski


Cglib was inlined into Spring as of version 3.2.0 as it is mentioned in the release notes of this version:

In prior versions, users of Spring's subclass-based AOP proxies (e.g. via proxy-target-class="true") and @Configuration class support were required to declare an explicit dependency on CGLIB 2.2. As of Spring Framework 3.2, we now repackage and inline the newly-released CGLIB 3.0.

This means greater convenience for users, as well as correct functionality for Java 7 users who are creating subclass proxies of types that contain invokedynamic bytecode instructions. Repackaging CGLIB internally ensures no classpath conflicts with other third party frameworks that may depend on other versions of CGLIB.

This was done to provide automatic updates that correlate with cglib and avoiding of version conflicts as cglib somestimes breaks its API.

like image 31
Rafael Winterhalter Avatar answered Oct 19 '22 17:10

Rafael Winterhalter