Java教程

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

本文主要是介绍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。要不然还会报错

 

这篇关于Spring Cloud Gateway java.lang.IllegalStateException: Invalid host: lb://manage_web的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!