我无法通过ApiGateway调用微服务。其给出如下 错误。
java.net.UnknownHostException: Failed to resolve 'ORDER-SERVICE' [A(1), AAAA(28)] after 2 queries at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1151) ~[netty-resolver-dns-4.1.111.Final.jar:4.1.111.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 POST "/api/order/create" [ExceptionHandlingWebHandler]
我看到有几个关于类似问题的问题。我已经尝试了所有的解决方案。但事情仍然没有解决。我正在使用
弹簧靴:3.3.1 春云版本:2023.0.3 爪哇:17
ApiGateway 属性
spring.application.name=api-gateway
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.instance.prefer-ip-address=true
eureka.instance.hostname=localhost
spring.cloud.gateway.discovery.locator.enabled=true
spring.cloud.gateway.discovery.locator.lower-case-service-id=true
spring.cloud.gateway.routes[0].id=ORDER-SERVICE
spring.cloud.gateway.routes[0].uri=http://ORDER-SERVICE/
spring.cloud.gateway.routes[0].predicates[0]=Path=/api/order/**
spring.cloud.discovery.enabled=true
订购服务
spring.application.name=order-service
eureka.instance.hostname=localhost
eureka.instance.prefer-ip-address=true
server.port=8082
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
spring.cloud.discovery.enabled=true
spring.cloud.gateway.discovery.locator.lower-case-service-id= true
spring.cloud.gateway.discovery.locator.enabled= true
api网关的依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
Discovery 服务器有 2 个正在运行的实例
如果您能找到解决方案,那将非常有帮助。
在这里您将
spring.cloud.gateway.routes[0].uri=http://ORDER-SERVICE/
替换为 spring.cloud.gateway.routes[0].uri=lb://ORDER-SERVICE
参考
http://ip-address {cannot be a service name}/
希望有帮助。