英文:
finishConnect(..) failed: Connection refused: localhost/127.0.0.1 , error: Webflux, Webclient, Spring boot, java
问题
我在使用本地主机中的 webclient 时遇到了这个错误,你们能帮我解决吗?
ERROR org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler - [0e1ef5cd-1] 500 服务器错误,HTTP GET "/product/spec/template/posts"。
product | io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) 失败:连接被拒绝:localhost/127.0.0.1:8090
product | 被抑制的异常:reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
product | 在以下位置观察到错误:
product | |_ checkpoint ⇢ 发起 GET 请求 http://localhost:8090/retailer/retailer/posts/12 [DefaultWebClient]
product | |_ checkpoint ⇢ 处理器 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 | 堆栈跟踪:
product | 由于:java.net.ConnectException: finishConnect(..) 失败:连接被拒绝
product | 在 io.netty.channel.unix.Errors.throwConnectException(Errors.java:124) ~[netty-transport-native-unix-common-4.1.51.Final.jar!/:4.1.51.Final]
英文:
I'm having this error while using webclient in localhost, can you help me guys ??
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]
答案1
得分: 3
不,我们不能直接通过localhost进行调用,这里的术语是“容器调用容器”,因此我们应该通过容器名称一起进行调用。
- 将docker-compose更改如下:
order-service:
build: docker/order-service
container_name: order-service
ports:
- 8082:8080
- 然后,在客户端服务中,我们只需像下面这样定义主机:
private String hostname = "http://order-service:8080/order-service/welcome";
您可以看到,当我们通过浏览器(真实客户端)调用订单服务时,我们通过扩展端口(8082)进行调用,但在容器调用容器的情况下,我们应该通过容器的名称和端口(8080)进行调用。
英文:
No, we can not call direct by localhost, the term here is "container call container", so, we should call together by container name.
- change the docker-compose like this:
> order-service:
> build: docker/order-service
> container_name: order-service
> ports:
> - 8082:8080
- And then, in the client service, we just define host like below:
> private String hostname =
> "http://order-service:8080/order-service/welcome";
You can see, when we call order service by browser (real client), we call throught extend port (8082), but in case container call container, we should call by its container
s name and it`s port (8080).
答案2
得分: 1
拒绝连接意味着在地址:端口上没有服务器正在监听。您可以使用 netstat -tulpen
命令检查哪些地址上打开了哪些端口。
英文:
Connection refused means that there was no server listening on the address:port. You can check with netstat -tulpen
what ports are open on which address.
答案3
得分: 0
我也遇到了相同的问题,在运行我的应用程序时,但我发现问题是在应用程序的 application.yml 中有两个同名的微服务。请确认您定义的所有微服务都具有唯一的名称和端口。
英文:
I also had the same issue, while running my application, but I found out that the issue was that I had two micro-services that were having the same name in the application.yml.
Kindly confirm that all the micro-services you have defined have unique name and ports.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论