【问题标题】:finishConnect(..) failed: Connection refused: localhost/127.0.0.1 , error: Webflux, Webclient, Spring boot, javafinishConnect(..) 失败:连接被拒绝:localhost/127.0.0.1,错误:Webflux、Webclient、Spring boot、java
【发布时间】:2020-12-10 18:20:51
【问题描述】:

我在 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]

【问题讨论】:

  • 检查是否有任何东西在 127.0.0.1:8090 上运行。使用sudo lsof -i -P -n | grep 8090

标签: java spring-boot netty webclient spring-webflux


【解决方案1】:

不行,我们不能直接通过localhost调用,这里的术语是“容器调用容器”,所以,我们应该通过容器名称一起调用。

  1. 像这样更改 docker-compose:
order-service:
  build: docker/order-service
  container_name: order-service
  ports:
    - 8082:8080
  1. 然后,在客户端服务中,我们只定义主机,如下所示:

私有字符串主机名 = "http://order-service:8080/order-service/welcome";

你可以看到,当我们通过浏览器(真实客户端)调用订单服务时,我们通过扩展端口(8082)调用,但是如果容器调用容器,我们应该通过它s containers名称和它的端口来调用(8080)。

【讨论】:

    【解决方案2】:

    连接被拒绝意味着没有服务器监听地址:端口。您可以通过netstat -tulpen 查看在哪个地址上打开了哪些端口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      • 2017-12-04
      • 2011-07-26
      相关资源
      最近更新 更多