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

Spring Boot 2.6.0+集成Swagger/OpenAPI版本兼容报错求助

问题分析与解决方案

核心原因

报错里的class file version 61.0对应Java 17,说明项目中混入了用Java17编译的springdoc依赖,但当前运行环境是Java11,导致版本不兼容。你声明的是SpringFox 2.9.2(Swagger的另一种实现),问题出在依赖传递引入了springdoc的包,和主动引入的SpringFox产生冲突。

解决步骤

  • 排查依赖来源
    用依赖分析命令找出带进来springdoc的依赖:

    • Maven执行:mvn dependency:tree
    • Gradle执行:./gradlew dependencies
      在输出结果中搜索springdoc,定位到引入它的父依赖。
  • 排除冲突依赖
    在引入springdoc的父依赖中,添加排除规则,移除所有springdoc相关模块:

    <dependency>
        <!-- 替换为带进来springdoc的那个依赖,比如某个starter -->
        <groupId>xxx</groupId>
        <artifactId>xxx</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springdoc</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • 验证版本兼容性
    SpringFox 2.9.2适配Spring Boot 2.1.x~2.3.x版本,确保你的Spring Boot版本在这个范围内,避免因版本不匹配引发其他问题。

  • 清理缓存重新构建
    清除依赖缓存后重新构建项目,避免缓存中的旧依赖干扰:

    • Maven:mvn clean install -U
    • Gradle:./gradlew clean build --refresh-dependencies

额外建议

SpringFox已停止维护,若长期维护项目,建议迁移到SpringDoc OpenAPI(适配Spring Boot 3+和Java17+),但迁移前需完全移除SpringFox相关依赖,避免冲突。

内容的提问来源于stack exchange,提问作者prabhat kumar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 21:42:40