jdk21 upgrade, asm reports error Unsupported class file major version 65

environment

jdk21 upgrade, asm error, spring-core version 5.3.18, project springboot version 2.6.6

Error details

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

I originally thought it was a problem with the asm package, and I upgraded asm to 9.6, but it was not for that reason. After investigation, it was because the spring-core5.3.18 version supports jdk19 at the highest level
The supported version is hard-coded, here:
org.springframework.asm.Opcodes#V19
Version verification:
org.springframework.asm.ClassReader#ClassReader(byte[], int, boolean)
File location:
D:/xxx/maven_repository/org/ springframework/spring-core/5.3.18/spring-core-5.3.18-sources.jar!/org/springframework/asm/ClassReader.java:197

Treatment measures

Upgrade spring-core version, overall springboot upgrade
Browsespring.ioOfficial website

Click Projects → SpringBoot
Insert image description here

Current mainstream versions:

Insert image description here

Support hours:

Insert image description here

upgrade

Here you can choose to upgrade to springboot2.7.x, or because you choose jdk21, you can choose to directly upgrade springboot to 3.2.x once and for all.

After upgrading the springboot project, refresh the project and use maven to re-import.

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

Project runs successfully

Looking back at the spring-core version: 5.3.31

Guess you like

Origin blog.csdn.net/qq_27577113/article/details/134895868