springcloud的应用向eureka注册中心注册失败,报错如下:com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
解决方法:
先确定注册中心是否已经启动,如果注册中心已启动,并可以访问,那就注意再要注册的应用中添加下面红色的代码。
1.注册中心配置
server:
port: 18081 # 指定该Eureka实例的端口
eureka:
instance:
hostname: localhost # 指定该Eureka实例的主机名
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
2.要注册的应用配置
application:
name: all-in-one # 项目名称尽量用小写
eureka:
client:
register-with-eureka: true
fetch-registry: true
serviceUrl:
defaultZone: http://localhost:18081/eureka/ # 指定注册中心的地址
instance:
preferIpAddress: true
ribbon:
eureka:
enabled: false