4

我是 Spring 新手,我需要让一个项目在 JDK7 上使用 Eclipse 成功运行。该项目以前在 JDK6 上运行。

我拥有属于原始项目的所有源文件和 jar。但是当我尝试运行它时,我得到以下异常:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\Users\e\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\DMControl\WEB-INF\classes\com\...\...\...\MyClass.class]; nested exception is java.lang.IncompatibleClassChangeError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor

我唯一的线索是我第一次尝试运行它时,我收到一个错误,说我没有

org.springframework.core.io.support.SpringFactoriesLoader. 

我查看了我的 spring-core-3.1.2.RELEASE.jar 并且确实没有 SpringFactoriesLoader。检查当前版本,我发现缺少的类确实在 spring-core-3.2.2.RELEASE.jar 中。

所以我把弹簧罐换成了最新版本。但是现在我在这个问题的标题中得到了例外。

任何的想法?

完整的堆栈跟踪:

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\Users\e\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\FTAdControl\WEB-INF\classes\com\fashiontraffic\adcontrol\health\restwebservices\HealthWSImpl.class]; nested exception is java.lang.IncompatibleClassChangeError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:281)
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242)
at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84)
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
at javax.servlet.GenericServlet.init(GenericServlet.java:242)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1190)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1103)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284)
at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.IncompatibleClassChangeError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:63)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:102)
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:257)
... 38 more
4

4 回答 4

10

@Eddy,听起来你的类路径上有来自 Spring 3.1 和 3.2 的 jar,这并不总是很糟糕,但有时它们不能很好地结合在一起。

当我添加 spring-hateoas 0.4 时,我在 Spring 3.2.2 项目中遇到了同样的错误,它引入了 spring-webmvc 3.1.x 及其所有 Spring 3.1 依赖项。

我排除了 Spring 3.1 依赖项,一切都很好。希望有帮助。

于 2013-04-04T17:23:01.873 回答
3

这是由于 jar 的版本不兼容。您可以在此博客中找到更多详细信息。

于 2013-07-02T08:48:03.140 回答
0
<org.springframework-version>**4.2.1.RELEASE**</org.springframework-version> 

在 pom.xml (属性属性)中将发布版本更改为最新版本

然后在所有 springframework 依赖项中引用该属性。

这对我有用!

于 2015-09-10T02:26:52.177 回答
0

就我而言,问题是因为我使用的是包含旧 Spring 版本的 activemq-all 库(目前我使用的是 Spring 4.2.4.RELEASE),所以我用 activemq-core 库对其进行了更改,问题就解决了。

于 2016-02-11T04:36:53.310 回答