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

从SpringFox迁移至SpringDoc后出现'/v3/api-docs'处理方法冲突如何解决

问题原因

报错核心是SpringFox和SpringDoc两个框架都注册了/v3/api-docs路径的处理方法,即使你删除了pom中直接引入的SpringFox依赖,也可能因为缓存、间接依赖、残留配置导致SpringFox的相关Bean仍然被加载。

解决步骤
  • 第一步:清理本地缓存
    先执行Maven清理命令强制刷新依赖:
    mvn clean install -U
    再清理IntelliJ IDEA缓存:打开顶部菜单「File → Invalidate Caches...」,勾选「Clear file system cache and local history」后重启IDEA,排除IDE缓存的旧依赖影响。
  • 第二步:排查并排除间接依赖
    执行以下命令排查所有间接引入的SpringFox依赖:
    (Linux/Mac系统)mvn dependency:tree | grep springfox
    (Windows系统)mvn dependency:tree | findstr springfox
    如果找到有其他依赖间接引入了SpringFox组件,在对应依赖中添加全局排除:
    <dependency>
        <groupId>引入SpringFox的依赖组名</groupId>
        <artifactId>引入SpringFox的依赖构件名</artifactId>
        <version>对应版本</version>
        <exclusions>
            <exclusion>
                <groupId>io.springfox</groupId>
                <artifactId>*</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
    也可以在IDEA中打开pom.xml右键选择「Diagrams → Show Dependencies」,搜索springfox关键词快速定位间接依赖来源。
  • 第三步:删除SpringFox残留配置
    全局搜索项目中带有@EnableSwagger2、@EnableOpenApi(SpringFox版本注解)的配置类,全部删除。
    同时删除application.yml/application.properties中所有springfox前缀的配置项,避免Spring上下文加载SpringFox的相关Bean。
  • 第四步:验证清理结果
    启动项目后检查IDEA的External Libraries目录,确认没有io.springfox开头的依赖包,之后访问http://localhost:8080/swagger-ui/index.html即可正常打开SpringDoc的接口文档页面。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 14:48:05