我正试图用弹簧罐来解决一个问题。我用很旧的罐子做一个很老的项目。
对于一个项目,我的依赖树拥有Spring 2.0.1,而对于另一个项目,它现在拥有Spring 2.0.2。它们都是依赖于一个jar :spring core:jar:1.0m3。
我遇到的问题是下面的例外:原来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和Spring定义任何版本,我定义的唯一版本是父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()那里得到了NoSuchMethodError for XmlSchemaCollection.read()的想法,用它我找到了两个罐子。正如Harini所建议的,我已经尝试了排除依赖关系,但它仍然没有工作,所以我只是重构了我的代码,使其只有一个src,而且在战争中也是如此(在野苍蝇中,war用它自己的类加载器加载它的库),所以在重构之后,我也遇到了同样的问题:
我是如何知道这是jar问题的,我对jvm做了详细的介绍,并看到了以下内容:
从vfs:/content/DirectRegistryServlet-1.0-SNAPSHOT.war/WEB-INF/lib/spring-core-2.0.1.jar加载org.springframework.util.ClassUtils
发布于 2015-11-12 04:25:29
看一下我正在使用的org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean代码,它实际上是导致问题的原因,在春季2.0.1中,这个FactoryBean并没有提到ClassUtils.getConstructorIfAvailable,这是很好的。正是Spring-2.0.2或spring-support-2.0.2.jar也有这个类,这个行就是这个调用所在的地方。
(我看错了类,因为问题是MethodInvokingJobDetailFactoryBean来自不同的jar,而不是Spring2.0.1.jar,spring 2.0.1实际上使用spring,它使用spring-support2.0.2.jar,它具有相同的MethodInvokingJobDetailFactoryBean )所以我解决了它:只创建了一个库来删除库,或者排除了也有这个类并解决它的库。
奇怪的是,我无法理解在windows上,它是如何在没有问题的情况下工作的,而在Linux和unix上,它给出了一个问题。
发布于 2015-11-12 00:15:05
在spring core:jar:1.0-m3依赖项中,不包含spring核心版本,而您不是using.Check,它是针对依赖项排除的。
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
https://stackoverflow.com/questions/33662226
复制相似问题