如何在生产中关闭swagger-ui [英] How do you turn off swagger-ui in production
问题描述
我已经昂首阔步地插入了我的Spring Boot应用程序. Spring Boot允许您为所拥有的每个环境拥有属性文件.有没有一种方法可以在生产环境中禁用摇摇欲坠?
将您的swagger配置放入单独的配置类中,并使用@Profile
注释->对其进行注释,以便仅在某些配置文件中将其扫描到Spring上下文中./p>
示例:
@Configuration
@EnableSwagger2
@Profile("dev")
public class SwaggerConfig {
// your swagger configuration
}
然后您可以通过以下命令行定义您的Spring Boot应用程序正在运行的配置文件:--spring.profiles.active=dev
或通过配置文件:spring.profiles.active=dev
.
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?
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.
Example:
@Configuration
@EnableSwagger2
@Profile("dev")
public class SwaggerConfig {
// your swagger configuration
}
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
.
Read this section of Spring Boot docs for more info about @Profile
这篇关于如何在生产中关闭swagger-ui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!