栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot 整合 swagger2

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot 整合 swagger2

配置介绍
环境版本
springboot2.7.0
swagger2.9.2
Pom依赖
    
    
        org.springframework.boot
        spring-boot-starter-web
    
    
        io.springfox
        springfox-swagger2
        2.9.2
    
    
        io.springfox
        springfox-swagger-ui
        2.9.2
    

    
        org.springframework.boot
        spring-boot-starter-test
        test
    

配置类
package com.timon.demo.config;

import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@Configuration(proxyBeanMethods = false)
@EnableSwagger2
public class SwaggerConfig {

    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")  // 需要映射到swagger文档中的路径
                .select()   // api选择构建器
                  // 需要配置到swagger文档中的接口
                .apis(RequestHandlerSelectors.basePackage("com.timon.controller")) 
                .paths(PathSelectors.any()) // 所有接口都配合配置到swagger
                .build().apiInfo(new ApiInfoBuilder()
                        .title("文档标题")       // 当前文档标题
                        .description("文档描述")
                        .version("版本")
                        .contact(new Contact("Timon",
                         "https://blog.csdn.net/weixin_41934575?type=blog", 
                         "543272045@qq.com"))
                        .build());
    }
}

问题解决 ApplicationContextException: Failed to start bean ‘documentationPluginsBootstrapper’
在SpringBoot2.6.0以后的版本中将SpringMVC 默认路径匹配策略从AntPathMatcher 更改为PathPatternParser

【解决方案一】
application.properties文件中添加:

spring.mvc.pathmatch.matching-strategy = ant_path_matcher

指定使用ant_path_matcher进行路径匹配;

【解决方案二】
升级swagger版本
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/975242.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号