简体   繁体   English

Spring CGLIB 和 CGLIB 有什么区别?

[英]What's the difference between Spring CGLIB and CGLIB?

Spring 不包含 cglib 依赖,cglib 和 spring cglib 都有Enhancer类,一个是net.sf.cglib.proxy.Enhancer而另一个是org.springframework.cglib.proxy ,它们之间有什么区别?

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.这样做的原因是使用 Spring 的项目可能想要使用 cglib 本身。 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.如果 Spring 有一个特定版本的 cglib 作为依赖项,那么使用 Spring 的项目就不可能选择不同的版本。 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.但是如果 Spring 使用不同包中重新打包的 cglib,则不存在版本冲突,并且项目可以根据需要使用任何版本的 cglib。

Some projects repackage Guava, Netty or other popular libraries in a similar manner.一些项目以类似的方式重新打包 Guava、Netty 或其他流行的库。

Cglib was inlined into Spring as of version 3.2.0 as it is mentioned in the release notes of this version : Cglib 从 3.2.0 版开始被内联到 Spring 中,因为它在这个版本发行说明中提到:

In prior versions, users of Spring's subclass-based AOP proxies (eg via proxy-target-class="true") and @Configuration class support were required to declare an explicit dependency on CGLIB 2.2.在之前的版本中,Spring 的基于子类的 AOP 代理(例如通过 proxy-target-class="true")和 @Configuration 类支持的用户需要声明对 CGLIB 2.2 的显式依赖。 As of Spring Framework 3.2, we now repackage and inline the newly-released CGLIB 3.0.从 Spring Framework 3.2 开始,我们现在重新打包并内联新发布的 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.这意味着为用户提供了更大的便利,并为创建包含调用动态字节码指令的类型的子类代理的 Java 7 用户提供了正确的功能。 Repackaging CGLIB internally ensures no classpath conflicts with other third party frameworks that may depend on other versions of CGLIB.在内部重新打包 CGLIB 可确保不会与可能依赖于其他 CGLIB 版本的其他第三方框架发生类路径冲突。

This was done to provide automatic updates that correlate with cglib and avoiding of version conflicts as cglib somestimes breaks its API.这样做是为了提供与 cglib 相关的自动更新并避免版本冲突,因为 cglib 有时会破坏其 API。

Spring shipped with repackaged cglib. Spring 附带重新打包的 cglib。 You can see actual cglib version in Gradle buildfile .您可以在 Gradle buildfile 中查看实际的 cglib 版本。 Search for word "cglib" and you find it:搜索单词“cglib”,你会找到它:

// As of Spring 4.0.3, spring-core includes asm 5.x and repackages cglib 3.2, inlining
// both into the spring-core jar. cglib 3.2 itself depends on asm 5.x and is therefore
// further transformed by the JarJar task to depend on org.springframework.asm; this
// avoids including two different copies of asm unnecessarily.
def cglibVersion = "3.2.4"

No difference, just a repackaging没有区别,只是重新包装


ps.附: class ObjenesisCglibAopProxy extends CglibAopProxy

Objenesis aims to overcome these restrictions by bypassing the constructor on object instantiation. Objenesis 旨在通过绕过对象实例化的构造函数来克服这些限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM