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

Spring Boot 3+Gradle启动遇ClassNotFoundError:springdoc依赖适配问题

解决方案

1. 确认依赖版本兼容性

Spring Boot 3.x 要求 springdoc-openapi-starter-webmvc-ui 版本至少为 2.0.0,你当前使用的2.7.0本身兼容,但要确保项目中没有引入低版本的Spring Framework依赖——这类依赖会覆盖Spring Boot 3自带的高版本框架包,导致类找不到。

2. 补充WebJars相关依赖

LiteWebJarsResourceResolver 属于Spring Web MVC的WebJars支持模块,若项目未自动引入相关依赖,需手动添加到build.gradle.kts:

implementation("org.webjars:webjars-locator-core:0.52")
implementation("org.webjars:swagger-ui:5.17.14")

3. 排查依赖冲突

执行Gradle命令查看spring-webmvc的依赖树,确认是否存在版本冲突:

./gradlew dependencyInsight --dependency org.springframework:spring-webmvc

如果发现有低版本的spring-webmvc被第三方依赖引入,直接在对应依赖声明中排除冲突:

implementation("第三方依赖组:依赖名:版本号") {
    exclude(group = "org.springframework", module = "spring-webmvc")
}

4. 验证Spring Boot插件配置

确保build.gradle.kts中正确应用Spring Boot插件,让Spring Boot统一管理依赖版本:

plugins {
    id("org.springframework.boot") version "3.x.x" // 替换为你实际使用的Spring Boot版本
    id("io.spring.dependency-management") version "1.1.4"
    kotlin("jvm") version "1.9.20"
    kotlin("plugin.spring") version "1.9.20"
}

dependencyManagement {
    imports {
        mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
    }
}

5. 清理并重新构建

执行命令清理缓存、刷新依赖后重新构建:

./gradlew clean build --refresh-dependencies

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 10:42:02