場景:
在啟動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/