天天看点

SpringCloud 配置${spring.cloud.client.ipAddress}

配置注册到Eureka的相同服务的多个实例,使用ip注册
配置${spring.cloud.client.ipAddress}
eureka:
   instance:
     prefer-ip-address: true
     instance-id: ${spring.cloud.client.ipAddress}:${spring.application.name}:${server.port}:@project.version@
 重启服务。。。然后Duang~
好吧,没这么简单
首先想到版本问题,一顿百度果然,springboot2.x后改为${spring.cloud.client.ip-address}
最终配置为
eureka:
   instance:
     prefer-ip-address: true
     instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}:@project.version@
 重启服务。。。OK如果还不行则在pom中加入
        <dependency>
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-commons</artifactId>
         </dependency>
 源码中 ${spring.cloud.client.ip-address}这个类是在spring-cloud-commons项目中