How do you turn off swagger-ui in production(如何在生产中关闭 swagger-ui)
问题描述
我已经大摇大摆地插入了我的 Spring Boot 应用程序.Spring boot 允许您拥有每个环境的属性文件.有没有办法在生产环境中禁用 swagger?
I have swagger plugged in to my spring boot application. Spring boot allows you to have property files for each environment that you have. Is there a way to disable swagger for a production environment?
推荐答案
将你的 swagger 配置放到单独的配置类中,并用 @Profile
注释进行注释 -> 以便将其扫描到 Spring 上下文中仅在某些配置文件中.
Put your swagger configuration into separate configuration class and annotate it with @Profile
annotation -> so that it will be scanned into Spring context only in certain profiles.
例子:
@Configuration
@EnableSwagger2
@Profile("dev")
public class SwaggerConfig {
// your swagger configuration
}
您可以通过命令行定义您的 Spring Boot 应用程序正在运行的配置文件:--spring.profiles.active=dev
或通过配置文件:spring.profiles.active=dev
.
You can than define profile your Spring Boot app is operating in via command line: --spring.profiles.active=dev
or via config file: spring.profiles.active=dev
.
阅读本节 Spring Boot有关 @Profile
这篇关于如何在生产中关闭 swagger-ui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在生产中关闭 swagger-ui


- 如何指定 CORS 的响应标头? 2022-01-01
- 转换 ldap 日期 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01