我尝试在 Windows 10 上使用 Consul 执行 Spring Boot jar 文件。首先我在 Windows 10 上安装了 Consul。然后我执行 Spring Boot jar 文件。供您参考,下面是 application.properties。
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
并且http://localhost:8500/ui
在网络浏览器上可以成功发现服务。但是我将spring boot项目docker化了。运行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进行docker化之前,我的项目与consul连接无误。但是在dockerizing之后,连接被拒绝了。dockerzing时我会错过任何程序吗?任何回复将不胜感激。