在研究Spring Cloud的过程中,本地搭建好Eureka注册中心之后,发现Eureka服务页面显示的服务是机器名:端口的格式,并不是IP+端口的形式
spring.application.name=compute-service
server.port=2223
spring.cloud.client.ipAddress=192.168.43.177
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${spring.application.name}:${server.port}
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
spring cloud不同版本的配置可能不同,比较老的版本是eureka.instance.preferIpAddress=true替代eureka.instance.prefer-ip-address=true
在实际的使用过程中,我发现eureka.instance.prefer-ip-address=true其实并不是必须的,只要配置
spring.cloud.client.ipAddress=192.168.43.177
eureka.instance.instance-id=${spring.cloud.client.ipAddress}:${spring.application.name}:${server.port}