由于java.net.ConnectException而无法找到PropertySource:连接被拒绝

时间:2018-07-18 02:22:30

标签: spring docker spring-boot docker-compose microservices

我创建了一个docker映像并将其推送到docker hub。现在,我尝试使用docker-compose在远程计算机上运行它,并收到以下错误。

java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
my-test_1  |    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:132)
my-test_1  |    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:93)
my-test_1  |    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:567)
my-test_1  |    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:338)
my-test_1  |    at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
my-test_1  |    at net.ptidej.seodin.SeodinApp.main(SeodinApp.java:68)
my-test_1  |    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
my-test_1  |    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
my-test_1  |    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
my-test_1  |    at java.lang.reflect.Method.invoke(Method.java:498)
my-test_1  |    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
my-test_1  |    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
my-test_1  |    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
my-test_1  |    at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
my-test_1  | Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8761/config/seodin/prod/master": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
my-test_1  |    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:674)
my-test_1  |    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:621)
my-test_1  |    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:539)
my-test_1  |    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:172)
my-test_1  |    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:93)
my-test_1  |    ... 13 common frames omitted
my-test_1  | Caused by: java.net.ConnectException: Connection refused (Connection refused)
my-test_1  |    at java.net.PlainSocketImpl.socketConnect(Native Method)
my-test_1  |    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
my-test_1  |    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
my-test_1  |    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
my-test_1  |    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
my-test_1  |    at java.net.Socket.connect(Socket.java:589)
my-test_1  |    at java.net.Socket.connect(Socket.java:538)
my-test_1  |    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
my-test_1  |    at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
my-test_1  |    at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
my-test_1  |    at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
my-test_1  |    at sun.net.www.http.HttpClient.New(HttpClient.java:339)
my-test_1  |    at sun.net.www.http.HttpClient.New(HttpClient.java:357)
my-test_1  |    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1220)
my-test_1  |    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1156)
my-test_1  |    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1050)
my-test_1  |    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:984)
my-test_1  |    at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:78)
my-test_1  |    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
my-test_1  |    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
my-test_1  |    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:112)
my-test_1  |    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator$GenericRequestHeaderInterceptor.intercept(ConfigServicePropertySourceLocator.java:237)
my-test_1  |    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:88)
my-test_1  |    at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:72)
my-test_1  |    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
my-test_1  |    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
my-test_1  |    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:660)
my-test_1  |    ... 17 common frames omitted
my-test_1  | 

我猜测它与其中一个配置文件中的端口有关,但我不知道哪个。此错误的含义是什么,我应该在哪里解决?我会很感激在源代码/配置文件中出现问题的任何线索/提示。谢谢。

2 个答案:

答案 0 :(得分:0)

您的Spring Boot应用程序配置为从在以下位置指定的Spring Cloud Config服务器加载属性

http://localhost:8761/config/seodin/prod/master

它看不到。

在Docker中运行时,请确保配置服务器也在Docker中运行,并且将Spring Boot应用配置为指向该服务器(URL不会是localhost;它很可能是容器名称如果您是在Docker中运行配置服务器,或者是外部配置服务器的URL)

答案 1 :(得分:0)

当您位于Docker容器中时,localhost会解析为该容器,而不是Docker Host。因此,应在应用程序配置中将Config Server的IP地址更改为Docker Host的IP地址或您的LAN IP地址。当然,如果您的计算机中正在运行Config Server,它将可以正常工作。

相关问题