jdk21升级,asm报错Unsupported class file major version 65

2023-12-13 10:12:30

环境

jdk21升级,asm报错,spring-core版本5.3.18,项目springboot版本为2.6.6

报错明细

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 [F:\xxx\App.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 65
	at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:60)
	at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:49)
	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:429)
	... 20 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 65
	at org.springframework.asm.ClassReader.<init>(ClassReader.java:199)
	at org.springframework.asm.ClassReader.<init>(ClassReader.java:180)
	at org.springframework.asm.ClassReader.<init>(ClassReader.java:166)
	at org.springframework.asm.ClassReader.<init>(ClassReader.java:287)
	at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:57)
	... 24 common frames omitted

本来还以为是asm包的问题,还特意把asm升级到了9.6,但不是因为那个原因,而经排查是因为spring-core5.3.18版本最高支持jdk19导致的
支持版本写死了,在这里:
org.springframework.asm.Opcodes#V19
版本校验:
org.springframework.asm.ClassReader#ClassReader(byte[], int, boolean)
文件位置:
D:/xxx/maven_repository/org/springframework/spring-core/5.3.18/spring-core-5.3.18-sources.jar!/org/springframework/asm/ClassReader.java:197

处理措施

升级spring-core版本,整体springboot升级
浏览spring.io官网

点击Projects → SpringBoot
在这里插入图片描述

现阶段各主流版本:

在这里插入图片描述

支持时间:

在这里插入图片描述

升级

这里可以选择升级到springboot2.7.x,或者因为选择jdk21,选择直接将springboot干到3.2.x一劳永逸

将springboot项目升级后,刷新项目,使用maven重新import

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.18</version>
        <relativePath/>
    </parent>

项目成功运行

回头再看spring-core版本:5.3.31

文章来源:https://blog.csdn.net/qq_27577113/article/details/134895868
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。