具有不同树的相同 jar 的依赖项

dependencies for same jar having different trees

我正在尝试解决 spring jar 的问题。我正在为一个非常古老的项目使用非常古老的罐子。

对于一个项目,我的依赖树现在有 spring-core 2.0.1,而另一个项目现在有 Spring-core 2.0.2。它们都作为一个 jar 的依赖项出现:spring-ws-core:jar:1.0-m3.

我遇到的问题是下面的异常:原来是 ClassUtils 从 2.0.1 更改为 2.0.2,错过了这个方法。 :

ERROR [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 94) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityLoadJob' defined in class path resource [dri-applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.getConstructorIfAvailable(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/reflect/Constructor;
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:443)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:245)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
        at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
        at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
        at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:195)
        at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
        at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.run(UndertowDeploymentService.java:82)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
        at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.getConstructorIfAvailable(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/reflect/Constructor;
        at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean.<clinit>(MethodInvokingJobDetailFactoryBean.java:73)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:84)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:60)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:52)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:640)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:626)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:381)
        ... 20 more



[INFO] com.sar.registry:MyServlet:war:1.0-SNAPSHOT
[INFO] +- com.sar.registry:DirectRegistry:jar:1.0-SNAPSHOT:compile
[INFO] |  +- com.sar.common:Common-Utils:jar:SNAPSHOT:compile
[INFO] |  +- com.sar.common:Common-Integration:jar:SNAPSHOT:compile
[INFO] |  +- org.springframework:spring:jar:2.0.1:compile
***[INFO] |  +- org.springframework.ws:spring-ws-core:jar:1.0-m3:compile***
[INFO] |  |  +- org.springframework.ws:spring-xml:jar:1.0-m3:compile
[INFO] |  |  +- org.springframework:spring-context:jar:2.0.1:compile
[INFO] |  |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  |  +- org.springframework:spring-web:jar:2.0.2:compile
[INFO] |  |  +- org.springframework:spring-webmvc:jar:2.0.2:compile
[INFO] |  |  |  \- org.springframework:spring-support:jar:2.0.2:compile
[INFO] |  |  +- stax:stax-api:jar:1.0:compile (version managed from 1.0.1)
[INFO] |  |  +- wsdl4j:wsdl4j:jar:1.6.1:compile
***[INFO] |  |  +- org.springframework:spring-core:jar:2.0.1:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:2.0.1:compile***
[INFO] |  +- org.springframework.ws:spring-oxm:jar:1.0-m3:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] |  +- xml-security:xmlsec:jar:1.3.0:compile
[INFO] |  +- wss4j:wss4j:jar:1.5.0:compile
[INFO] |  +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.16:provided (scope managed from compile)
[INFO] |  |  \- org.jvnet.mimepull:mimepull:jar:1.7:provided
[INFO] |  +- quartz:quartz:jar:1.5.2:compile
[INFO] |  \- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] +- com.sar.registry:MyAppApi:jar:1.0-SNAPSHOT:compile
[INFO] +- javax.servlet:servlet-api:jar:2.4:provided
[INFO] +- net.sf.saxon:saxon:jar:8.7:runtime
[INFO] +- org.springframework:spring-jmx:jar:2.0.1:runtime
[INFO] +- net.sf.saxon:saxon-dom:jar:8.7:runtime
[INFO] +- axis:axis:jar:1.4:runtime
[INFO] |  +- axis:axis-wsdl4j:jar:1.5.1:runtime
[INFO] |  \- commons-discovery:commons-discovery:jar:0.2:runtime
[INFO] +- taglibs:standard:jar:1.1.2:runtime
[INFO] +- javax.servlet:jstl:jar:1.1.2:runtime
[INFO] +- org.springframework:spring-mock:jar:2.0.1:test
[INFO] |  \- junit:junit:jar:3.8.1:test
[INFO] +- xmlunit:xmlunit:jar:1.0:test
[INFO] \- hsqldb:hsqldb:jar:1.8.0.7:test
[INFO] ------------------------------------------------------------------------

另一个:

[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ MyApp ---
[INFO] com.sar.registry:MyApp:jar:1.0-SNAPSHOT
[INFO] +- com.sar.registry:MyAppApi:jar:1.0-SNAPSHOT:compile
[INFO] +- com.sar.common:Common-Utils:jar:SNAPSHOT:compile
[INFO] +- com.sar.common:Common-Integration:jar:SNAPSHOT:compile
[INFO] +- org.springframework:spring:jar:2.0.1:compile
***[INFO] +- org.springframework.ws:spring-ws-core:jar:1.0-m3:compile***
[INFO] |  +- org.springframework.ws:spring-xml:jar:1.0-m3:compile
[INFO] |  +- org.springframework:spring-context:jar:2.0.2:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-web:jar:2.0.2:compile
[INFO] |  +- org.springframework:spring-webmvc:jar:2.0.2:compile
[INFO] |  |  \- org.springframework:spring-support:jar:2.0.2:compile
[INFO] |  +- stax:stax-api:jar:1.0:compile (version managed from 1.0.1)
[INFO] |  +- wsdl4j:wsdl4j:jar:1.6.1:compile
***[INFO] |  +- org.springframework:spring-core:jar:2.0.2:compile
[INFO] |  \- org.springframework:spring-beans:jar:2.0.2:compile***
[INFO] +- org.springframework.ws:spring-oxm:jar:1.0-m3:compile
[INFO] +- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] +- xml-security:xmlsec:jar:1.3.0:compile
[INFO] +- wss4j:wss4j:jar:1.5.0:compile
[INFO] +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.16:compile
[INFO] |  \- org.jvnet.mimepull:mimepull:jar:1.7:compile
[INFO] +- quartz:quartz:jar:1.5.2:compile
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- log4j:log4j:jar:1.2.8:test
[INFO] +- xmlunit:xmlunit:jar:1.0:test
[INFO] +- hsqldb:hsqldb:jar:1.8.0.7:test
[INFO] +- org.springframework:spring-mock:jar:2.0.1:test
[INFO] +- xerces:xercesImpl:jar:2.8.1:test
[INFO] +- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] +- net.sf.saxon:saxon:jar:8.7:test (scope not updated to runtime)
[INFO] +- net.sf.saxon:saxon-dom:jar:8.7:test
[INFO] \- axis:axis:jar:1.4:test
[INFO]    +- org.apache.axis:axis-jaxrpc:jar:1.4:test
[INFO]    +- org.apache.axis:axis-saaj:jar:1.4:test
[INFO]    +- axis:axis-wsdl4j:jar:1.5.1:test
[INFO]    \- commons-discovery:commons-discovery:jar:0.2:test

在我的 poms 中,我没有为 Spring-beans 和 Spring-core 定义任何版本,我定义的唯一版本是在父 Pom 中,即 org.springframework.ws: spring-ws-core:jar:1.0-m3:compile

现在两个拥有相同 jar 的项目怎么可能拥有完全不同的依赖 jar。我在 Maven3,wildfly9,java8。

此外,奇怪的是,同一个 war 文件在我的本地 windows wildfly9 上工作正常,但它在 SunOS 和 Linux 机器上给我错误。

编辑: 我从 NoSuchMethodError for XmlSchemaCollection.read() 得到了 dependencyTree 的想法 并使用它我找到了两个罐子。正如 Harini 所建议的那样,我已经尝试排除依赖关系但它仍然没有用所以我只是将我的代码重构为只有一个 src 并且在 war 中也是如此(在 wildfly war 中加载在它自己的带有库的类加载器中)所以在重构之后,我也遇到了同样的问题:

我是如何知道这是 jar 问题的,因为我在我的 jvm 上做了详细说明并看到了这个:

[从 vfs 加载 org.springframework.util.ClassUtils:/content/DirectRegistryServlet-1.0-SNAPSHOT.war/WEB-INF/lib/spring-core-2.0.1.jar]

在 spring-ws-core:jar:1.0-m3 依赖项中排除你不是 spring-core 的版本 using.Check 排除依赖项。

https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

查看我正在使用的 org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean 的代码实际上是导致问题的代码,事实证明在 spring 2.0.1 中这个 FactoryBean 没有提到ClassUtils.getConstructorIfAvailable 这很好。它是 Spring-2.0.2 或 spring-support-2.0.2.jar 也有此 class 与此调用所在的行。

(我看错了 class 因为问题是 MethodInvokingJobDetailFactoryBean 来自不同的 jar 而不是来自 spring-2.0.1.jar, Spring-ws-2.0.1 实际上使用 spring-mvc,它使用 spring-support2.0.2.jar 具有相同的 MethodInvokingJobDetailFactoryBean )所以我解决了它:只制作一个库来获取MethodInvokingJobDetailFactoryBean 删除了库或排除了也有此 class 的库并解决了它。

奇怪的是,我无法理解它在 windows 上如何正常工作,而在 Linux 和 unix 上却出现问题。