Spring Cloud Gateway java.lang.IllegalStateException: Invalid host: lb://manage_web
阿新 • • 發佈:2022-04-22
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。要不然還會報錯