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();
}
}

