You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Spring Boot 2.1.8.RELEASE迁移至2.7.7遇ASM类解析错误求助

解决Spring Boot 2.7.7迁移后ASM不支持Java17类文件的问题

问题原因

错误ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet. Unsupported class file major version 61是因为当前依赖中的ASM版本无法识别Java17编译的类文件(major version 61对应Java17)。虽然Spring Boot 2.7.7官方支持Java17,但可能存在依赖冲突,导致旧版本ASM被引入。

解决方案

1. 强制升级ASM版本

在项目构建文件中强制指定兼容Java17的ASM版本(至少9.3及以上,ASM 9.x系列支持Java16+):

Maven(pom.xml)示例:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm</artifactId>
            <version>9.5</version>
        </dependency>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm-commons</artifactId>
            <version>9.5</version>
        </dependency>
        <dependency>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm-tree</artifactId>
            <version>9.5</version>
        </dependency>
    </dependencies>
</dependencyManagement>

Gradle(build.gradle)示例:

configurations.all {
    resolutionStrategy.force 'org.ow2.asm:asm:9.5'
    resolutionStrategy.force 'org.ow2.asm:asm-commons:9.5'
    resolutionStrategy.force 'org.ow2.asm:asm-tree:9.5'
}

2. 统一编译与运行Java版本

确保项目编译配置的Java版本和运行时一致:

Maven(pom.xml):

<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
</properties>

Gradle(build.gradle):

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

3. 清理重建项目

执行命令清理旧编译文件和依赖缓存,重新构建:

  • Maven:mvn clean install
  • Gradle:./gradlew clean build

4. 检查第三方依赖

排查项目中使用的第三方库,确认它们是否支持Java17。部分老旧库可能依赖低版本ASM,需要升级这些库到兼容Java17的版本。


内容的提问来源于stack exchange,提问作者Amir Choubani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 18:45:59