How do you turn off swagger-ui in production

前端 未结 6 1627
孤独总比滥情好
孤独总比滥情好 2021-01-31 14:46

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 fo

6条回答
  •  无人共我
    2021-01-31 15:22

    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

提交回复
热议问题