学习篇:基于swagger2.7.0-集成springboot2.1.x

一、springBoot集成swagger

参看文档:https://springfox.github.io/springfox/docs/current/#springfox-swagger-ui

1. 集成方式
  • Maven集成

<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>2.7.0</version>
</dependency>

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


  • Gradle集成

repositories {

  jcenter()

}



dependencies {

    compile "io.springfox:springfox-swagger2:2.7.0"

    compile "io.springfox:springfox-swagger-ui:2.7.0"

}

2. 注入swagger配置bean

/**
 * @ClassName SwaggerConfig
 * @Description TODO
 * @Author eastern
 * @Date 2019/8/12 下午4:41
 * @Version 1.0
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket controllerApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("controller")
                .apiInfo(apiInfo())
                .select()
                // 只显示xx Controller下的api 包路径
                 .apis(RequestHandlerSelectors.basePackage(ProductController.class.getPackage().getName()))
                // 只显示以products开头的api
                // .paths(PathSelectors.ant("/products/*"))
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("HTTP API")
                .description("Swagger测试接口")
                .termsOfServiceUrl("http://springfox.io")
                .license("Apache License Version 2.0")
                .contact(new Contact("zhangsan", "", "xxxxxxx@qq.com"))
                .version("2.0")
                .build();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值