简体   繁体   English

Hibernate和Jersey依赖项冲突(javassist)-谁能解释这是如何工作的?

[英]Hibernate and Jersey dependency conflict (javassist) - can anyone explain how this works?

I'm currently using hibernate-4.1.4 and jersey-2.22. 我目前正在使用hibernate-4.1.4和jersey-2.22。 These have javassist-3.15 and javassist-3.18 respectively. 它们分别具有javassist-3.15和javassist-3.18。

I included both hibernate and jersey in my project and to my surprise, there were no dependency conflicts between the said javassists. 我将冬眠和运动衫都包括在我的项目中,令我惊讶的是,上述Javassists之间没有依赖冲突。

I was wondering how Java tells hibernate to use 3.15 and how it tell jersey to use 3.18 since both are in the build path. 我想知道Java如何告诉hibernate使用3.15,以及它如何告诉jersey使用3.18,因为两者都在构建路径中。 Is one javassist not being used? 是否没有使用一个javassist?

Follow up question: Let's say that javassist-3.15 and javassist-3.18 have a conflict with each other. 后续问题:假设javassist-3.15和javassist-3.18彼此冲突。 How do I resolve this? 我该如何解决? Do I disable both javassists and include one externally? 我是否禁用两个javassists并在外部包含一个?

EDIT: My app is a web app that runs on Tomcat 7. We don't use Maven/Gradle. 编辑:我的应用程序是在Tomcat 7上运行的Web应用程序。我们不使用Maven / Gradle。 We just configure the dependencies by putting the jars in the build path using Eclipse. 我们只是通过使用Eclipse将jar放入构建路径来配置依赖项。

JAVA loads classes through ClassLoaders ... Many applications servers, as Tomcat or Wildfly, implement and use their own class loaders (not the regular ones of the common JDK) ... So you must check the Tomcat documentation to read about its classloading behaviour... JAVA通过ClassLoader加载类...许多应用程序服务器(例如Tomcat或Wildfly)实现并使用自己的类加载器(而不是常见JDK的常规类加载器)...因此,您必须查看Tomcat文档以了解其类加载行为...

After saying that, is very likely that Tomcat is loading libraries in alphabetical order. 这么说之后,Tomcat很可能会按字母顺序加载库。 I Explain... 我解释...

Suppose that you use a class named: Dummy , and this class is contained at the libraries: dummy-1.0.jar and dummy-1.1.jar ... when the class Dummy is requested, the Tomcat ClassLoader search for that class definition, looking first at dummy-1.0.jar and later at dummy-1.1.jar ... given that dummy-1.0.jar contains that class, Tomcat stops looking a returns that class version ... If dummy-1.0.jar would not have the target class, the dummy-1.1.jar class version would be returned instead... 假设您使用一个名为Dummy的类,并且该类包含在以下库中: dummy-1.0.jardummy-1.1.jar ...当请求类Dummy时,Tomcat ClassLoader搜索该类定义,查找首先在dummy-1.0.jar ,然后在dummy-1.1.jar ...考虑到dummy-1.0.jar包含该类,Tomcat会停止查找该类版本的返回值...如果dummy-1.0.jar将没有目标类,则将返回dummy-1.1.jar类版本...

(I suggest to try this to validate the container behaivour, it's not so hard to implement)... (我建议您尝试使用此方法来验证容器的行为,实现起来并不难)...

And yes, if javassist-3.15 and javassist-3.18 conflicts with each other, you should remove them and pick the javassist JAR more 是的,如果javassist-3.15javassist-3.18相互冲突,则应删除它们并选择javassist JAR
suitable for both libraries (jersey and hibernate). 适用于两个库(球衣和休眠)。

As thumb rule, I tend to pick the newest library (the one with greater version), but this scheme not always work... 按照经验法则,我倾向于选择最新的库(版本更高的库),但是这种方案并不总是可行的...

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

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