1、报错如下

  1. 2020-07-31 13:57:30.792 ERROR 23180 --- [freshExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GATEWAYZUUL/Fcant:GatewayZuul:8762 - was unable to refresh its cache! status = Cannot execute request on any known server
  2. com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
  3. at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-1.9.21.jar:1.9.21]
  4. at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.21.jar:1.9.21]
  5. at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.21.jar:1.9.21]
  6. at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.9.21.jar:1.9.21]
  7. at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.21.jar:1.9.21]
  8. at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1081) [eureka-client-1.9.21.jar:1.9.21]
  9. at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:995) [eureka-client-1.9.21.jar:1.9.21]
  10. at com.netflix.discovery.DiscoveryClient.refreshRegistry(DiscoveryClient.java:1517) [eureka-client-1.9.21.jar:1.9.21]
  11. at com.netflix.discovery.DiscoveryClient$CacheRefreshThread.run(DiscoveryClient.java:1484) [eureka-client-1.9.21.jar:1.9.21]
  12. at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_192]
  13. at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_192]
  14. at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_192]
  15. at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_192]
  16. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_192]
  17. at java.lang.Thread.run(Thread.java:748) [na:1.8.0_192]

2、问题分析及解决

A.客户端指定的注册中心地址不一致导致无法注册至注册中心

错误情况

image.png

正例情况

服务端URL

  1. server:
  2. port: 8761
  3. eureka:
  4. instance:
  5. #eureka实例的主机名
  6. hostname: localhost
  7. client:
  8. register-with-eureka: false #是否把服务注册中心注册到eureka
  9. fetch-registry: false #是否从服务注册中心注册eureka获取注册信息
  10. service-url:
  11. defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

客户端指定注册中心的URL

  1. server:
  2. port: 8762
  3. eureka:
  4. client:
  5. service-url:
  6. # 将网关注册到注册中心
  7. defaultZone: http://127.0.0.1:8761/eureka/

B.客户端与服务端都需要指定 /eureka/ 接口,否则也无法进行注册

C.服务端指定了server.**servlet.context-path,而客户端没有添加该访问的接口也会无法成功注册**

错误示例

image.png

正确示例

image.png