[英]Two jars having same package name, same class name and same method name
I am facing this problem in spring boot application where I am using Two jars. 我在使用两个罐子的spring boot应用程序中遇到此问题。 And in those jars there are two classes with the same package name and same class name and one method with the same name .
在这些jar中,有两个类具有相同的程序包名称和相同的类名称,以及一个方法具有相同的名称。 Problem occurs when class loader loads the class from different jar and tries to call this method, If jar A is loaded first then method is called and everything works fine , But if jar B is called first then, NOSUCHMETHODERROR exception is thrown at runtime.
当类加载器从不同的jar加载类并尝试调用此方法时,会发生问题。如果首先加载jar A,则调用方法,并且一切正常,但是如果首先调用jar B,则在运行时引发NOSUCHMETHODERROR异常。 Can you please help to fix this.
您能帮忙解决此问题吗? Is there a way by which I can force the classloader to load a particular jar first, always in Spring boot app, Or probably any other fix for this.
有没有一种方法可以强制类加载器首先在Spring Boot应用程序中首先加载特定的jar,或者可能对此进行任何其他修复。
NOTE: I am using JAVA 8 and I don't have access to the source code of these jar files. 注意:我正在使用JAVA 8,但无权访问这些jar文件的源代码。
If you are loading those jars as a dependency you could exclude it from Maven via 如果您将这些罐子作为依赖项加载,则可以通过以下方式将其从Maven中排除
<exclusions>
<exclusion>
<groupId>org.XXXX</groupId>
<artifactId>jar1-api</artifactId>
</exclusion>
</exclusions>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.