自定义spring cloud eureka client的instance-id 博客分类: spring boot 实践笔记 eureka client instance-id
程序员文章站
2024-03-13 18:49:57
...
环境:spring cloud Finchley.RC2,spring boot 2.0.2.RELEASE,eureka 1.9.0
.properties文件增加如下配置:
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port} eureka.instance.prefer-ip-address=true
.yml文件则增加以下配置:
eureka: instance: instance-id: ${spring.cloud.client.ip-address}:${server.port} prefer-ip-address: true
注意一点:
spring cloud Finchley.RC2及以后版本,spring.cloud.client.ipAddress改为了spring.cloud.client.ip-address,如果你还写成spring.cloud.client.ipAddress,将报如下错误:
Failed to bind properties under 'eureka.instance.instance-id' to java.lang.String: Property: eureka.instance.instance-id Value: ${spring.cloud.client.ipAddress}:${server.port} Origin: class path resource [application.yml]:22:18 Reason: Could not resolve placeholder 'spring.cloud.client.ipAddress' in value "${spring.cloud.client.ipAddress}:${server.port}"