美文网首页
springboot2.7整合swagger2

springboot2.7整合swagger2

作者: 早起的大艺术家 | 来源:发表于2023-06-05 10:58 被阅读0次

    1、引入依赖两个
    <dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
    </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
    

    2、新建配置类:
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    @Bean
    public Docket getDocket(){
    ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
    apiInfoBuilder.title("《蜂蜜商城》接口文档说明")
    .description("此文档详细说明了蜂蜜商城后台接口规范")
    .version("v 1.0.0")
    .contact(new Contact("yogo","www.yogo.com","542870322@qq.com"));
    ApiInfo apiInfo = apiInfoBuilder.build();

        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.yogo.api"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
    

    }

    直接运行会报错:
    Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException:
    3、在yml中添加以下配置:
    spring:
    mvc:
    pathmatch:
    matching-strategy: ant_path_matcher

    ----------------------------------整合结束--------------------------------------

    4、第三方UI插件依赖,还挺好看的:
    <dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>swagger-bootstrap-ui</artifactId>
    <version>1.9.6</version>
    </dependency>

    相关文章

      网友评论

          本文标题:springboot2.7整合swagger2

          本文链接:https://www.haomeiwen.com/subject/cslbedtx.html