【问题标题】:Spring cloud gateway routes from consul来自 consul 的 Spring Cloud Gateway 路由
【发布时间】:2018-07-01 04:49:03
【问题描述】:

我不知道 spring-cloud-gateway 是否支持从 consul 注册表读取路由,就像 Zuul 一样。

我添加了spring-cloud-starter-consul-discovery依赖和@EnableDiscoveryClient,并在application.yml中配置了consul属性,但是,/actuator/gateway/routes没有显示任何来自consul的路由

我也尝试设置 spring.cloud.gateway.discovery.locator.enabled: true 但没有改变任何东西。 下面的示例:

spring:
  cloud:
    consul:
      discovery:
        register: false
          locator:
            enabled: true
        acl-token: d3ee84e2-c99a-5d84-e4bf-b2cefd7671ba
        enabled: true

所以主要的问题是,它甚至可以工作吗?

编辑:可能应该提到它是 2.0.0.M5 版本,带有 Spring Boot 2.0.0.M7

我也用 --debug 启动了,有这一行:

   GatewayDiscoveryClientAutoConfiguration#discoveryClientRouteDefinitionLocator:
  Did not match:
     - @ConditionalOnBean (types: org.springframework.cloud.client.discovery.DiscoveryClient; SearchStrategy: all) did not find any beans of type org.springframework.cloud.client.discovery.DiscoveryClient (OnBeanCondition)
  Matched:
     - @ConditionalOnProperty (spring.cloud.gateway.discovery.locator.enabled) matched (OnPropertyCondition)

【问题讨论】:

    标签: spring-cloud


    【解决方案1】:

    我可以通过声明以下 bean 来解决它:DiscoveryClientRouteDefinitionLocator (reference)

    @Configuration
    @EnableDiscoveryClient
    public class AutoRouting {
      @Bean
      public DiscoveryClientRouteDefinitionLocator discoveryClientRouteDefinitionLocator(DiscoveryClient discoveryClient, DiscoveryLocatorProperties properties) {
        return new DiscoveryClientRouteDefinitionLocator(discoveryClient, properties);
      }
    }
    

    P.S:你需要包含“spring-cloud-consul”

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      • 2023-01-21
      • 2019-08-03
      • 2019-03-31
      • 2019-09-23
      相关资源
      最近更新 更多