首页 > 其他分享 >解决Spring报错:Failed to read candidate component class: file [ ]; nested exception is org.

解决Spring报错:Failed to read candidate component class: file [ ]; nested exception is org.

时间:2024-08-08 21:27:11浏览次数:14  
标签:exception java candidate factory springframework 报错 beans context org

使用IDEA 建立一个很基础的Spring项目时,之前用xml方式,写bean标签一直正常使用,改用注解方式后发现报错,显示:

Exception in thread "XXX" org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [XXX.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [XXX.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 57
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:454)
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:316)
	at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:275)
	at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:90)
	at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1391)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1371)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:179)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:149)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:96)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:513)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:393)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:636)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
	at XXX(XXX:XXX)
Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [XXX.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 57
	at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:57)
	at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
	at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123)
	at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:430)
	... 25 more
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 57
	at org.springframework.asm.ClassReader.<init>(ClassReader.java:184)
	at org.springframework.asm.ClassReader.<init>(ClassReader.java:166)
	at org.springframework.asm.ClassReader.<init>(ClassReader.java:152)
	at org.springframework.asm.ClassReader.<init>(ClassReader.java:273)
	at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:54)
	... 28 more

最终发现,是Spring依赖与JDK版本不兼容导致。Spring创建时为低版本JDK,而最近运行此项目时使用的是现在安装的JDK22。于是将原先使用的 5.2.10.RELEASE 改为 6.1.0 报错解决。

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>6.1.10</version>
        </dependency>

对于Spring 依赖的版本选择,可查阅https://mvnrepository.com/artifact/org.springframework/spring-context/6.1.10

标签:exception,java,candidate,factory,springframework,报错,beans,context,org
From: https://www.cnblogs.com/jzxys/p/18349782

相关文章

  • CDH的CM金丝雀Canary报错
    CM金丝雀Canary报错1HDFS金丝雀Canary测试无法为/tmp/.cloudera_health_monitoring_canary_files创建父目录。2HiveMetastoreCanaryHiveMetastorecanary创建huehdfs主目录失败。检查:1)hdfs是否处于safemode,正常是off#hdfsdfsadmin-safemodegetSafe......
  • 关于java连接数据库时提示异常java.sql.SQLException: No suitable driver found for
    当我们测试一个新的数据库服务时,需要使用对方提供jdbc驱动来连接数据库,有时候简单的写个demo去连接,发现提示异常:java.sql.SQLException:Nosuitabledriverfoundforjdbc:jdbc:nuuv://10.1.8.99:8832/xxoo比如有以下程序连接数据库测试:publicstaticvoidmain(String[]a......
  • IgniteFAQ-2-CacheWriterException: Failed to write entries in database
    ignite同步或者异步落库数据到DB时,如果因为落库的数据不满足db库的要求,如长度、精度、nonull等限制,就会出现落库失败报Failedtowriteentriesindatabase错误。ignite异步落库默认时5秒或者10240条flush一次,失败的数据会不断尝试,当存在一条数据以为数据库要求失败时,会卡住此表......
  • Java 中 Exception 和 Error 有什么区别?
    1.ExceptionException代表程序正常运行过程中可以预料到的意外情况,应该被开发者捕获并进行相应处理。2.ErrorError指在正常情况下不太可能出现的情况。大部分Error导致程序处于不正常、不可恢复的状态,所以不便也不需被开发者捕获,因为这个情况下你捕获了也无济于事......
  • crictllog执行命令报错:ContainerStatus from runtime service failed“
    执行crictl有pod、但是crictllogs容器id有报错 解决方式:因crictllog查看的是container容器、这个容器是查看ctr中的容器见截图信息:查看容器信息:-n指定命名空间(k8s.容器默认是运行在k8s.io这个namespace下、所以需要指定)ctrpods 查看的只是头部信息、所以获取......
  • wpf 中的三个 UnhandledException
    结构化异常处理在异常点生成异常的结构体,异常分发WPF中的三个Excption处理函数AppDomain::UnhandledException事件属性UI线程和Thread实例的异常会触发该事件。Application::DispatcherUnhandledExcetion事件属性UI线程异常会触发该事件。如果事件的IsHandle=false,异......
  • Centos8下载报错:Errors during downloading metadata for repository ‘appstream‘:
    前提使用docker安装centos8步骤复现:启动后发现环境中没有vim功能,想着安装一下,发现报错:Errorsduringdownloadingmetadataforrepository'appstream':原因:找到AI工具翻译后:结合centos系统在2021年就没有在进行维护了,再进行网上大量查阅得知应该是yum源的问题,这里......
  • openssl make报错
    安装openssl时,make./config:error:theHTTPcachemodulerequiresmd5functionsfromOpenSSLlibrary.Youcaneitherdisablethemodulebyusing--without-http-cacheoption,orinstalltheOpenSSLlibraryintothesystem,orbuildtheOpenSSLlibrarystat......
  • 泛微OA移动端在公网IP变更和无法打开Install.do界面下修改插件库地址(122,128报错)
    事情起因因为公司搬迁,公网IP变更,服务器搬迁时未提前调整好泛微oa服务器的IP,但是旧地址仍留有主路由可以使用。发现问题移动端无法正常连接,/install.do的界面也无法打开,无法进入修改插件库服务器IP的页面联系了技术,技术表示/install.do无法打开的话也无能为力(因为公司维护费断......
  • uniapp Vue3版本使用jweixin-module报错
    把uniapp从Vue2版本选择到Vue3版本编译开发  改用到Vue3使用:varjweixin=require('jweixin-module')会编译报错:requireisnotdefined,没有require模块.改成import的话,由于jweixin-module不支持export写法,所以引入也不能成功1import *asjweixinfr......