Spring Boot 项目启动失败:Unsupported class file major version 64 错误解决
'\'2023-07-14 13:23:37.972'\' '\1\9\'ERROR'\9\' '\5\9\'76120'\9\' '\'---'\' '\'[ restartedMain]'\' '\6\9\'o.s.boot.SpringApplication '\9\' '\':'\' Application run failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [C:\Users\ASUS\Desktop\SpringBoot-YunPan-main\SpringBoot-YunPan-main\target\classes\com\bjpowernode\pan\PanApplication.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 [C:\Users\ASUS\Desktop\SpringBoot-YunPan-main\SpringBoot-YunPan-main\target\classes\com\bjpowernode\pan\PanApplication.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 64
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:454) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:316) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:275) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:287) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531) ~[spring-context-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202) ~[spring-boot-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at com.bjpowernode.pan.PanApplication.main(PanApplication.java:10) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:578) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.1.6.RELEASE.jar:2.1.6.RELEASE]
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 [C:\Users\ASUS\Desktop\SpringBoot-YunPan-main\SpringBoot-YunPan-main\target\classes\com\bjpowernode\pan\PanApplication.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 64
at org.springframework.core.type.classreading.SimpleMetadataReader.
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="url" value="jdbc:mysql://localhost:3306/mydatabase" />
<property name="username" value="root" />
<property name="password" value="123456" />
</bean>
在Java代码中通过Spring的依赖注入来获取mysql数据源位置。 这个如何获取内容:根据错误信息,问题出现在类文件的版本不受支持。错误信息中显示了 "Unsupported class file major version 64",这意味着类文件的主要版本是 64,而当前的环境不支持这个版本。
解决方法是将类文件的版本降低到支持的版本。可以通过以下步骤操作:
- 确认当前使用的 JDK 版本是否支持类文件的主要版本 64。你可以在命令行中输入
java -version来查看 JDK 版本。如果版本过低,升级 JDK 版本到支持的版本。 - 检查项目中是否有其他依赖或插件会引入类文件的版本 64。可以尝试更新这些依赖或插件到支持的版本。
- 如果项目中没有其他依赖或插件引入类文件的版本 64,那么可能是因为你使用了不兼容的编译器编译项目。尝试使用与当前环境兼容的编译器重新编译项目。
- 如果以上步骤都没有解决问题,可以尝试在项目的构建文件(如 pom.xml 或 build.gradle)中指定编译器的源和目标版本,确保与当前环境兼容。
请注意,如果你不确定如何操作,可以参考项目文档或咨询项目维护者获取更详细的指导。
原文地址: http://www.cveoy.top/t/topic/pMvb 著作权归作者所有。请勿转载和采集!