【问题标题】:Hide Feign client endpoints in Swagger在 Swagger 中隐藏 Feign 客户端端点
【发布时间】:2017-11-15 14:06:02
【问题描述】:

我正在使用 Springboot 自动配置,目前我所有的 Feign 端点都暴露在 swagger-ui 中。如何禁用此功能?

【问题讨论】:

    标签: spring spring-boot swagger netflix-feign


    【解决方案1】:

    您可以在application.properties 中将其设置为:

    endpoints.enabled=false
    endpoints.health.enabled=true
    endpoints.loggers.enabled=true
    

    在你的情况下,它会是这样的

    endpoints.feign.***=true
    

    但这并没有禁用招摇,而是端点暴露自己。例如,对于 Swagger,您必须使用 @Api#hidden() 显式标记它们。

    【讨论】:

      【解决方案2】:

      到目前为止,不包含不相关端点的最佳方法是通过 Swagger Docker,例如

      @Configuration
      @EnableSwagger2
      class SwaggerConf {
        @Bean
        Docket allApis() {
          return new Docket(DocumentationType.SWAGGER_2)
            .groupName("all")
            .select().apis(RequestHandlerSelectors.basePackage("com.example.base"))
            .build();
        }
      }
      

      【讨论】:

        【解决方案3】:

        对我有用的最简单的解决方案是将 @ApiIgnore 添加到 Feign 客户端

        @ApiIgnore    
        @FeignClient()
        public interface FeignApi {
        }
        

        【讨论】:

          猜你喜欢
          • 2020-12-20
          • 2011-11-25
          • 1970-01-01
          • 1970-01-01
          • 2014-11-26
          • 2019-11-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多