具有不同树的相同jar的依赖关系

时间:2015-11-12 00:09:39

标签: java spring maven jar dependencies

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

对于一个项目,我的依赖树有spring-core 2.0.1,而另一个项目现在有Spring-core 2.0.2。它们都是作为一个罐子的依赖而来的: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$1.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$1.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:编译

现在,具有相同jar的两个项目如何能够完全拥有不同的依赖jar。我在Maven3,wildfly9,java8上。

另外,不知何故,奇怪的是,同样的war文件在我的本地windows wildfly9上工作正常,但它在SunOS和Linux机器上给我错误。

编辑: 我从https://github.com/facebook/jest/tree/master/examples/react获得了dependencyTree Idea 并使用它我找到了两个罐子。正如Harini建议的那样,我已经尝试排除了依赖,它仍然没有工作所以我只是重构我的代码只有一个src而且在战争中也是如此(In Wildfly war在它自己的类加载器中加载它的libs)所以在重构之后,我也遇到了同样的问题:

我怎么知道这是罐子问题,我在jvm上做了一个冗长的事情并看到了这个:

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

2 个答案:

答案 0 :(得分:1)

在spring-ws-core:jar:1.0-m3依赖项中排除你没有使用的spring-core版本。请查看依赖项排除。

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

答案 1 :(得分:0)

在查看我正在使用的org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean的代码时,实际上是导致问题的代码,结果发现在Spring 2.0.1中,这个FactoryBean没有提到ClassUtils。 getConstructorIfAvailable这是好的。它是Spring-2.0.2 OR spring-support-2.0.2.jar这个类也有这个调用的行。

(我正在查看错误的类,问题是MethodInvokingJobDetailFactoryBean来自另一个jar而不是来自spring-2.0.1.jar,Spring-ws-2.0.1实际使用spring-mvc,它使用spring- support2.0.2.jar,它有相同的MethodInvokingJobDetailFactoryBean)所以我解决了它:只做了一个库来让MethodInvokingJobDetailFactoryBean删除了库,或者排除了那个也有这个类的库并解决了它。

奇怪的是,我无法理解在Windows上它是如何工作没有问题的,在Linux和unix上它给出了一个问题。