SpringBoot整合Swagger2以及生产环境的安全问题处理
https://www.cnblogs.com/i-tao/p/10548181.html
3.如果解决线上接口不被暴露?
3.1 使用springboot security过滤
略……
3.2 生产环境移除Swagger2
略……
3.3 直接使用多环境配置,生产环境不启用Swagger2
application.yml文件
spring:
profiles:
active: pro
application-pro.yml
#生产环境 server: port: 8080 swagger2: enable: false
2.2 Swagger2配置类增加
@Value("${swagger2.enable}") private boolean swagger2Enable;
package com.tao.springboot.util; import org.springframework.beans.factory.annotation.Value; 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; @Configuration public class Swagger2 { @Value("${swagger2.enable}") private boolean swagger2Enable; @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .enable(swagger2Enable) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.tao.springboot.action"))//controller路径 .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("标题") .description("描述") .termsOfServiceUrl("地址") .version("1.0") .build(); } }