如何在生产环境禁用 Swagger 2

时间:2025-03-21 09:31:21
@Configuration @EnableSwagger2WebMvc @ConditionalOnProperty(prefix = "swagger2", value = {"enable"}, havingValue = "true") public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .pathMapping("/") .select() .apis(RequestHandlerSelectors.basePackage("com.--.--.controller")) .paths(PathSelectors.any()) .build().apiInfo(apiInfo()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("****接口文档") .description("自动接口文档详细描述信息") .version("version1.0") .contact(new Contact("开发者:***项目组", "http://www.***.com", "***@***.com")) .license("The Apache License") .licenseUrl("/") .build(); } }