Org.apache.http.conn.HttpHostConnectException:连接到本地主机:8500[本地主机/127.0.0.1]失败:连接被拒绝(连接被拒绝)

wqlqzqxt  于 2022-10-23  发布在  Apache
关注(0)|答案(1)|浏览(1119)

我尝试在Windows 10上使用Consul执行Spring Boot JAR文件。首先,我在Windows 10上安装了Consul。然后我执行了Spring Boot JAR文件。供您参考,下面是应用程序.属性。

spring.cloud.consul.host=192.168.200.51
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.healthCheckInterval=300s
spring.cloud.consul.config.enabled=true
spring.application.name = blog-app-service

并且Web浏览器上的http://localhost:8500/ui可以成功发现该服务。但我把Spring Boot项目对接了。运行Docker容器成功。但与领事的连接失败。例外情况如下:

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8500 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
        at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:221) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165) ~[httpclient-4.5.8.jar!/:4.5.8]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:140) ~[httpclient-4.5.8.jar!/:4.5.8]
        at com.ecwid.consul.transport.AbstractHttpTransport.executeRequest(AbstractHttpTransport.java:61) ~[consul-api-1.4.1.jar!/:na]

在对接Spring Boot JAR之前,我的项目与Consul连接无误。但在对接后,连接被拒绝。停靠码头时,我错过了什么程序吗?

e5nqia27

e5nqia271#

从docker使用Host.docker.Internal作为您的计算机的主机。
我想从主机上的容器连接到服务
主机的IP地址不断变化(如果您没有网络访问权限,则为无)。从18.03开始,我们建议连接到特殊的DNS名称Host.docker.Internal,该名称可解析为主机使用的内部IP地址。这是出于开发目的,不能在Docker Desktop for Windows之外的生产环境中工作。
更多信息:https://docs.docker.com/docker-for-windows/networking/#known-limitations-use-cases-and-workarounds

相关问题