【问题标题】:How can I hide Swagger at production profile?如何在生产配置文件中隐藏 Swagger?
【发布时间】:2021-09-13 09:27:49
【问题描述】:

我尝试在SwaggerConfig 类上添加profile annotation
我用 !local 进行测试,看看它是否有效,然后我将其更改为:!prod

@profile("!local")

注解前的这张图片 before

注解后的这张图片 after

我认为某些东西正在触发Swagger。帮帮我:(
我的配置类

@Profile("!local")
@EnableSwagger2
@Configuration
public class SwaggerConfig{

    @Bean
    public Docket swaggerConfiguration() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("private packageName"))
                .paths(PathSelectors.regex("/.*"))
                .build());
    }

我的应用程序 yml 文件

spring:
    profiles:
      active: local

【问题讨论】:

  • 您应该向我们展示您的配置文件以及您如何启动/编译您的应用,以查看您的Spring 确实考虑了您的个人资料。
  • @Pilpo 我已编辑

标签: java spring swagger swagger-ui profile


【解决方案1】:

这个 sn-p 应该可以帮助您在 prod 中隐藏 swagger ui。

 @Profile({"!prod && !local"})
    @EnableSwagger2
    @Configuration
    public class SwaggerConfig{
    
        @Bean
        public Docket swaggerConfiguration() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("private packageName"))
                    .paths(PathSelectors.regex("/.*"))
                    .build());
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 2019-02-23
    相关资源
    最近更新 更多