springboot2,gradle集成swagger2
2021-02-14 13:20
标签:esc 访问 ice builder png autoconf arp yml idt gradle文件增加 添加配置类SwaggerConfig 生产环境建议不要启用swagger 配置如下 访问swagger http://localhost/swagger-ui.html 配置成功 springboot2,gradle集成swagger2 标签:esc 访问 ice builder png autoconf arp yml idt 原文地址:https://www.cnblogs.com/zzuuoo666/p/12722502.html// swagger
implementation "io.springfox:springfox-swagger2:2.9.2"
implementation "io.springfox:springfox-swagger-ui:2.9.2"
package com.zuo.model.config;
import org.springframework.context.annotation.Bean;
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.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2 //添加swagger启用注解
//@Profile({"dev", "test"}) //方式一
//@ConditionalOnProperty(name = "swagger2.enable", havingValue = "true") //方式二
public class SwaggerConfig {
//读取yml文件配置
@Value("${swagger2.enable}")
private boolean swagger2Enable;
/**
* .enable() 控制是否进行初始化
* .select() 初始化并返回一个API选择构造器
* .paths(PathSelectors.any()) 设置路径筛选器
* .apis(RequestHandlerSelectors.basePackage("com.xxx.xxx.xxx")) 添加路径选择条件
* .build(); 构建
*
* PathSelectors 类的方法:
* - Predicate
文章标题:springboot2,gradle集成swagger2
文章链接:http://soscw.com/index.php/essay/55227.html