spring BeanDefinitionStoreException 读取候选组件类失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22771826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
BeanDefinitionStoreException Failed to read candidate component class
提问by cpu2007
Can someone tell me how to solve this issue?
有人能告诉我如何解决这个问题吗?
I have narrowed down the problem to the pom.xml file. My project works but when I add the following dependency I get an error
我已将问题缩小到 pom.xml 文件。我的项目有效,但是当我添加以下依赖项时出现错误
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.3.2.RELEASE</version>
</dependency>
The error stack is as follow
错误堆栈如下
ERROR DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\workspace-sts\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Webtest1\WEB-INF\classes\com\springweb\controller\SetHomePageController.class]; nested exception is java.lang.IncompatibleClassChangeError: class org.springframework.core.type.classreading.ClassMetadataReadingVisitor has interface org.springframework.asm.ClassVisitor as super class
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:290) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:242) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:84) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1438) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) ~[spring-beans-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) ~[spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) ~[spring-web-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451) ~[spring-context-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459) ~[spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-3.2.3.RELEASE.jar:3.2.3.RELEASE]
at javax.servlet.GenericServlet.init(GenericServlet.java:160) [servlet-api.jar:3.0.FR]
at org.apache.catalina.core.Standar
I can't understand what is wrong with the dependency, I need spring-data jpa dependency later when I'm going to add a dao that uses extends JpaRepository.
我无法理解依赖项有什么问题,稍后当我要添加使用 extends JpaRepository 的 dao 时,我需要 spring-data jpa 依赖项。
Thanks in advance.
提前致谢。
回答by Aleksandr Dubinsky
Another reason is use of Spring 3 with Java 8. Java 8 requires Spring 4.
另一个原因是在 Java 8 中使用 Spring 3。Java 8 需要 Spring 4。
(not specific to this question, but for those who are googling the error message)
(不是针对这个问题,而是针对那些在谷歌上搜索错误信息的人)
回答by Emerson Farrugia
You most likely have conflicting Spring dependencies on your classpath. It's probably an old spring-asm
JAR.
您很可能在类路径上存在冲突的 Spring 依赖项。这可能是一个旧的spring-asm
JAR。
Run mvn dependency:tree -Dincludes=:spring*::
and check for conflicts. The best way to avoid these is to put a dependency on the spring-framework-bom
in your project's dependencyManagement
section, as follows
运行mvn dependency:tree -Dincludes=:spring*::
并检查冲突。避免这些的最好方法是spring-framework-bom
在您的项目dependencyManagement
部分中添加依赖项,如下所示
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.0.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
These versionsare supported.
支持这些版本。
回答by Vineeth Bhaskaran
I am using spring 3.2.3.RELEASE.When i changed the jdk.version1.8 to 1.6 in maven compiler plug-in it started working
我正在使用 spring 3.2.3.RELEASE。当我在 maven 编译器插件中将 jdk.version1.8更改为 1.6 时,它开始工作
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
回答by testuserx
If anyone is still facing this error and is refering the getting started guide from spring.io, not using the defaut package and placing your class files under a new package did the trick for me.
如果有人仍然面临这个错误并且正在参考 spring.io 的入门指南,那么不使用 defaut 包并将您的类文件放在一个新包下对我来说是诀窍。
回答by Anuj Joshi
When I tried to change the sequence of jars in the build path with
<classpathentry kind="lib" path="/CoreTrainSim-Software-COTS/spring_jars/spring-core-5.1.7.RELEASE.jar"/>
当我尝试使用以下命令更改构建路径中的 jar 序列时
<classpathentry kind="lib" path="/CoreTrainSim-Software-COTS/spring_jars/spring-core-5.1.7.RELEASE.jar"/>
it worked
有效
回答by NIKHIL NAGRALE
In my case I had dependencies that brought in the spring-asm dependency that conflicted with the latest Spring core. So in Dependency Hierarchy search for "asm"and exclude spring asm from all dependencies having it.
就我而言,我的依赖项带来了与最新 Spring core 冲突的spring-asm 依赖项。因此,在依赖层次结构中搜索“asm”并从所有依赖项中排除 spring asm。
My case: 1)
我的情况:1)
<dependency>
<groupId>org.restlet.jee</groupId>
<artifactId>org.restlet.ext.fileupload</artifactId>
<version>2.3.1</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
2)
2)
<dependency>
<groupId>org.restlet.jee</groupId>
<artifactId>org.restlet.ext.spring</artifactId>
<version>2.1.2</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
回答by user136776
I had a similar error due to a corrupted class file -- somehow the CI build had a zero bytes class file in the jar (despite a non-zero inner class file being present, others ok) - one broken file out of ~100 classes. It might have been a disk space issue, but took a while to realise (since the class was in a dependent project jar, built by Gradle into a fat-jar for a Spring Boot project).
由于类文件损坏,我遇到了类似的错误——不知何故,CI 构建在 jar 中有一个零字节的类文件(尽管存在非零内部类文件,但其他文件正常)——大约 100 个类中有一个损坏的文件. 这可能是磁盘空间问题,但花了一段时间才意识到(因为该类位于依赖项目 jar 中,由 Gradle 构建为 Spring Boot 项目的 fat-jar)。