finishconnect(..)失败:连接被拒绝:localhost/127.0.0.1,错误:webflux,webclient,spring boot,java

k97glaaz  于 2021-07-08  发布在  Java
关注(0)|答案(2)|浏览(4777)

我在localhost中使用webclient时遇到了这个错误,你们能帮我吗??

ERROR                  org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler - [0e1ef5cd-1]  500 Server Error for HTTP G
ET "/product/spec/template/posts"
product      | io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: localhost/127.0.0.1:8090
product      |  Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
product      | Error has been observed at the following site(s):
product      |  |_ checkpoint ⇢ Request to GET http://localhost:8090/retailer/retailer/posts/12 [DefaultWebClient]
product      |  |_ checkpoint ⇢ Handler com.zucco.tech.hm.service.product.controller.ProductSpecTemplateController#posts() [DispatcherHandler]
product      |  |_ checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
product      |  |_ checkpoint ⇢ HTTP GET "/product/spec/template/posts" [ExceptionHandlingWebHandler]
product      | Stack trace:
product      | Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused
product      |  at io.netty.channel.unix.Errors.throwConnectException(Errors.java:124) ~[netty-transport-native-unix-common-4.1.51.Final.jar!/:4.1.51.Final]
3gtaxfhh

3gtaxfhh1#

连接被拒绝意味着没有服务器在侦听address:port. 你可以和我核对一下 netstat -tulpen 哪些端口在哪个地址开放。

ni65a41a

ni65a41a2#

不,我们不能通过localhost直接调用,这里的术语是“container call container”,所以,我们应该通过container name一起调用。
更改docker组合如下:

order-service:
  build: docker/order-service
  container_name: order-service
  ports:
    - 8082:8080

然后,在客户机服务中,我们只定义如下主机:
专用字符串主机名=“http://order-service:8080/订单服务/欢迎”;
您可以看到,当我们通过浏览器(real client)调用订单服务时,我们通过扩展端口(8082)调用,但如果容器调用容器,我们应该通过它调用 s container 的名称和端口(8080)。

相关问题