Spring Cloud Gateway java.lang.IllegalStateException: Invalid host: lb://manage_web

java.lang.IllegalStateException: Invalid host: lb://manage_web
    at org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.filter(RouteToRequestUrlFilter.java:86) ~[spring-cloud-gateway-core-2.2.3.RELEASE.jar:2.2.3.RELEASE]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ org.springframework.web.cors.reactive.CorsWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ HTTP GET "/manage_web/v2/api-docs" [ExceptionHandlingWebHandler]
Stack trace:

Spring Cloud Gateway路由配置的时候,要负载均衡的服务名称不能写"_" 下划线

 

原有的错误配置:

    gateway:
      routes:
        - id: qq_route
          uri: http://localhost:8000/
          predicates:
            - Query=url,index
        - id: manage-web
          uri: lb://manage_web
          predicates:
            - Path=/manage_web/** # 匹配的规则
          filters:
            - StripPrefix=1

修改后的配置:

    gateway:
      routes:
        - id: qq_route
          uri: http://localhost:8000/
          predicates:
            - Query=url,index
        - id: manage-web
          uri: lb://manage-web
          predicates:
            - Path=/manage-web/** # 匹配的规则
          filters:
            - StripPrefix=1

同时要将你负载均衡的服务名称修改为manage-web,不再是manage_web。要不然还会报错

 

posted @ 2022-04-22 09:49  —阿峰—  阅读(318)  评论(0编辑  收藏  举报