有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我怎样才能隐藏在产品配置文件中的狂妄自大?

我试图在SwaggerConfig类上添加一个profile annotation
我用过!本地测试,看看它是否工作,然后我将它改为:!刺激

@profile("!local")

这是注释前的img before

这是注释后的img 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

共 (1) 个答案

  1. # 1 楼答案

    这段代码应该可以帮助您在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());
            }