gpt4 book ai didi

spring-boot - Spring Cloud API Gateway 路由不起作用

转载 作者:行者123 更新时间:2023-12-04 15:57:53 27 4
gpt4 key购买 nike

我使用以下技术设计了一个微服务原型(prototype)

  • Eureka 服务器(发现服务器)
  • Spring Boot(后端服务)
  • Spring Cloud API 网关

  • 上面提到的服务都起来了, ApI Gatewayback end services都注册到了 Eureka Server
    enter image description here
    API 网关路由配置
    server.port=8080
    eureka.client.serviceUrl.defaultZone = http://localhost:8083/eureka
    spring.application.name=ApiGateway
    spring.cloud.gateway.discovery.locator.enabled=true
    spring.cloud.gateway.discovery.locator.lower-case-service-id=true

    spring.cloud.gateway.routes[0].id=service1
    spring.cloud.gateway.routes[0].uri=lb://MICROSERVICE1
    spring.cloud.gateway.routes[0].predicates[0]=Path=/service1/**
    微服务配置
    server.port=8081
    server.address=127.0.0.1
    eureka.client.serviceUrl.defaultZone = http://localhost:8083/eureka
    spring.application.name=MicroService1
    error.whitelabel.enabled= false
    Controller
    @RestController
    @RequestMapping("/service1")
    public class HomeController {
    @GetMapping("/message")
    public String hello() {
    return "response from micro service1";
    }

    }
    当我向网关发送请求时,它显示以下错误
    2020-12-16 22:26:09.770 ERROR 16700 --- [ctor-http-nio-3] a.w.r.e.AbstractErrorWebExceptionHandler : [d3334561-1]  500 Server Error for HTTP GET "/service1/message"

    java.net.UnknownHostException: failed to resolve 'LAPTOP-KU56B6A8' after 3 queries
    at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1013) ~[netty-resolver-dns-4.1.55.Final.jar:4.1.55.Final]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
    Error has been observed at the following site(s):
    |_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ HTTP GET "/service1/message" [ExceptionHandlingWebHandler]
    我们如何解决上述问题。

    最佳答案

    我已经修改了 API 网关路由配置,如下所示

    spring.cloud.gateway.routes[0].id=service1
    spring.cloud.gateway.routes[0].uri=http://localhost:8081/service1/
    spring.cloud.gateway.routes[0].predicates[0]=Path=/service1/**
    现在工作正常

    关于spring-boot - Spring Cloud API Gateway 路由不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65333590/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com