Spring Cloud系列(五) 修改服务的实例名为ip+端口(Finchley.RC2版本)

在我的这篇文章Eureka配置详解说过,Spring Cloud Eureka 将服务的instanceId默认设置为

 ${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}

这种默认的方式在实际开发时不是我们想要的,我们需要改成ip地址+端口的形式。

修改如下配置

spring:
  application:
    name: hello-service #为服务命名
server:
  port: 2222
eureka:
  client:
    service-url: 
      defaultZone: http://localhost:1111/eureka/ #指定服务注册中心位置
  instance:
    prefer-ip-address: true #使用ip地址
    instance-id: ${spring.cloud.client.ip-address}:${server.port}

访问Eureka面板

 

注意:我的Spring Cloud版本这样写${spring.cloud.client.ip-address},如果你的版本找不到该属性应该是使用${spring.cloud.client.ipAddress}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值