随笔 - 48  文章 - 0  评论 - 0  阅读 - 14116

014 springboot2.7.10与swagger3.0.0出现的版本冲突问题,以及解决办法

springboot2.7.10集成Swagger3.0.0过程中出现的错误提示

翻译过来:

解决办法:

1. 网上的解决办法1: 在配置文件中添加以下内容

1
2
3
4
spring:
  mvc: # 解决springboot2.7.10与swagger3版本冲突的问题
    pathmatch:
      matching-strategy: ant_path_matcher

 结果报错,springboot直接无法启动

解决办法二:在创建好的SwaggerConfig中添加上@EnableWebMvc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.example.mag_springboot01.config;
 
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
 
@Configuration
@EnableOpenApi
@EnableWebMvc  //解决Springfox3.0与2.6.0及以上版本的冲突的问题
public class SwaggerConfig {
    /**
     * 创建API应用
     * apiInfo() 增加API相关信息
     * 通过select() 函数返回一个A屁SelectBuilder实例,用来控制哪些接口暴漏给Swagger来展现
     * 本例采用扫描的包路径来定义指定要建立API的目录
     * @return
     */
    @Bean
    public Docket restApi() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("标准接口")
                .apiInfo(apiInfo("后台管理系统", "1.0"))// 用于生成API文档
                .useDefaultResponseMessages(true)
                .forCodeGeneration(false)
                .select()//select()函数返回一个ApiSelectorBuilder实例,用来控制接口被Swagger做成文档
                .apis(RequestHandlerSelectors.basePackage("com.example.mag_springboot01.controller"))
                .paths(PathSelectors.any())//选择所有的API,如果你想只为部分API生成文档,可以配置在这里
                .build();
 
    }
    private ApiInfo apiInfo(String title, String version) {
        return new ApiInfoBuilder()
                .title(title)
                .version(version)
                .description("更多关注")
                .contact(new Contact("zzq", "zzq123.com", "zzq@qq.com"))
                .build();
 
    }
}

访问的时候记得带上port,如http://localhost:8081/swagger-ui/index.html

 题外话: 遇到解决不了的问题,不要直接就放弃,而是到网上去搜,搜到的方法一个一个去试,要想着,这个问题我能遇到,别人肯定也会遇到。直到解决自己面临的问题,加油 ヾ(◍°∇°◍)ノ゙

问题顺利解决,嘻嘻 (#^.^#)

 

posted on   zzq156  阅读(137)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示