我正在从2.x升级到SpringFox Swagger 3.0.0,它引入了SpringFox springfox-boot-starter依赖项,它消除了对基于2.x的SwaggerConfig的需求。
/**
* NO LONGER NEEDED
*/
@Configuration
@EnableSwagger2
@Profile({"local", "dev", "beta"}) // <- HOW TO DISABLE IN PROD INSTEAD OF THIS
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}现在我不再需要这个@Configuration,它允许我在@Profile中指定我的环境配置文件,从而在生产中禁用Swagger,如何在SpringFox Swagger-UI 3.x中禁用生产中的Swagger?
注意:对于一些人来说,有一些基于Security的接触讨论过的这里可能是一个选项,但由于两个原因,这个场景不是一个选项:
spring-boot-security-starter依赖项发布于 2021-05-07 18:02:42
答案并不容易找到,而且SpringFox的迁移指南或文档这里 (应该在哪里)中也找不到答案。
SwaggerUI3.0.0的正确且迄今为止最好的答案是这里。
只需将springfox.documentation.enabled=[true|false]添加到目标环境的application.properties或application.yml。
顺便提一下,最好能看到SpringFox文档中列出的所有可用SpringFox属性的列表。
https://stackoverflow.com/questions/67439123
复制相似问题