错误:Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to localhost:8761 timed out

详细错误:

 1 com.sun.jersey.api.client.ClientHandlerException: org.apache.http.conn.ConnectTimeoutException: Connect to localhost:8761 timed out
 2     at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
 3     at com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.7.2.jar:1.7.2]
 4     at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.7.2.jar:1.7.2]
 5     at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
 6     at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
 7     at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]
 8     at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) ~[jersey-client-1.19.1.jar:1.19.1]
 9     at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.7.2.jar:1.7.2]
10     at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:71) ~[eureka-core-1.7.2.jar:1.7.2]
11     at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.7.2.jar:1.7.2]
12     at java.lang.Thread.run(Thread.java:748) [na:1.8.0_202]
13 Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to localhost:8761 timed out
14     at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123) ~[httpclient-4.5.8.jar:4.5.8]
15     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ~[httpclient-4.5.8.jar:4.5.8]
16     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.8.jar:4.5.8]
17     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.8.jar:4.5.8]
18     at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:605) ~[httpclient-4.5.8.jar:4.5.8]
19     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:440) ~[httpclient-4.5.8.jar:4.5.8]
20     at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.8.jar:4.5.8]
21     at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.8.jar:4.5.8]
22     at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.8.jar:4.5.8]
23     at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
24     ... 10 common frames omitted

疑问:我哪里根本没有使用到端口为:8761  的应用,经过一番百度查阅,终于让我找到答案了。原来问题出在  EurekaClientConfigBean 这个类,源码如下:

 1 package org.springframework.cloud.netflix.eureka;
 2 import ...
 3 @ConfigurationProperties("eureka.client")
 4 public class EurekaClientConfigBean implements EurekaClientConfig {
 5     public static final String PREFIX = "eureka.client";
 6     public static final String DEFAULT_URL = "http://localhost:8761/eureka/";  // 问题的所在,原来 springcloud 源码这里定义了
 7     public static final String DEFAULT_ZONE = "defaultZone";
 8     private static final int MINUTES = 60;
 9     @Autowired(
10         required = false
11     )
12     .....
13     public EurekaClientConfigBean() {
14         this.serviceUrl.put("defaultZone", "http://localhost:8761/eureka/");
15         this.gZipContent = true;
16         this.useDnsForFetchingServiceUrls = false;
17         this.registerWithEureka = true;
18         this.preferSameZoneEureka = true;
19         this.availabilityZones = new HashMap();
20         this.filterOnlyUpInstances = true;
21         this.fetchRegistry = true;
22         this.dollarReplacement = "_-";
23         this.escapeCharReplacement = "__";
24         this.allowRedirects = false;
25         this.onDemandUpdateStatusChange = true;
26         this.clientDataAccept = EurekaAccept.full.name();
27         this.shouldUnregisterOnShutdown = true;
28         this.shouldEnforceRegistrationAtInit = false;
29     }
30     ...
31 }

解决方案:使用你的端口号去覆盖里面的端口,即:

eureka.client.service-url.defaultZone=http://eureka1:5121/eureka/  // 写你的ip及端口

 

posted @ 2019-06-17 21:10  梦在原地  阅读(15967)  评论(0编辑  收藏  举报