Swagger 3.0.0: Can#39;t disable in production without SwaggerConfig and @Profile(Swagger 3.0.0:没有 SwaggerConfig 和 @Profile 就无法在生产中禁用)
问题描述
我正在从 2.x 升级到 SpringFox Swagger 3.0.0,它引入了 Spring Boot 启动器 springfox-boot-starter 依赖项,无需基于 2.x 的 SwaggerConfig:
I'm upgrading to SpringFox Swagger 3.0.0 from 2.x, which introduces the Spring Boot starter springfox-boot-starter dependency that obviates the need for the 2.x-based 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,我该如何禁用 Swagger在 SpringFox Swagger-UI 3.x 中生产?
Now that I no longer need this @Configuration, which allows me to specify my environment profiles in @Profile and therefore disable Swagger in production, how do I disable Swagger in production in SpringFox Swagger-UI 3.x?
注意:这里讨论了基于 Spring Security 的方法对某些人来说是一种选择,但在这种情况下不是一种选择,原因有两个:
NOTE: There is Spring Security-based approached discussed here that could be an option for some, but is not an option for this scenario for two reasons:
- 我的应用程序没有使用 Spring Security,并且无法包含
spring-boot-security-starter依赖项 - 它需要将所有其他端点列入白名单才能让它们再次工作,这是不可接受的
推荐答案
答案并不容易找到,并且不在 SpringFox 的迁移指南或文档中 这里(应该在哪里).
The answer was not easy to find and was NOT in SpringFox's migration guide or documentation here (where it should be).
Swagger UI 3.0.0 的正确且迄今为止最好的答案是此处.
The CORRECT and by far best answer for Swagger UI 3.0.0 is here.
只需将 springfox.documentation.enabled=[true|false] 添加到目标环境的 application.properties 或 application.yml.
Just add springfox.documentation.enabled=[true|false] to the target environment's application.properties or application.yml.
顺便说一句,很高兴看到 SpringFox 文档中列出的所有可用 Spring Boot 属性列表的部分.
As an aside, it would be nice to see a section with the list of all available Spring Boot properties listed in the SpringFox doc.
这篇关于Swagger 3.0.0:没有 SwaggerConfig 和 @Profile 就无法在生产中禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Swagger 3.0.0:没有 SwaggerConfig 和 @Profile 就无法在生产中禁用
基础教程推荐
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
