場景:
在啟動eureka server時,出現以下錯誤:
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
問題解決:
檢視配置檔案application.yml,發現register-with-eureka 屬性值設定為true了,將其改為false,重啟eureka服務,啟動成功,問題解決
原因:
在預設設定下,eureka服務註冊中心也會將自己作為客戶端來嘗試註冊它自己,所以我們需要禁用它的客戶端註冊行為:
eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false
總結:
若是未禁用eureka服務註冊中心的客戶端註冊行為,需提供service-url註冊中心地址:
server: port: 8091 eureka: instance: hostname: localhost client: register-with-eureka: true fetch-registry: false #註冊中心地址 service-url: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/