随笔 - 657,  文章 - 0,  评论 - 116,  阅读 - 153万

场景

SpringCloud中集成Eureka实现集群部署服务注册与服务提供者:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/124710576

在上面集群搭建的基础上,对于服务提供者如果有多个主机,只能看到主机名,不能很直观的看到

是哪个ip。

 

 

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

1、项目中引入actuator依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

2、找到Eureka Client(服务提供者)的application.yml配置文件

添加如下配置

  instance:
    instance-id: payment8001
    #访问路径可以显示IP地址
    prefer-ip-address: true

完整pom文件

复制代码
server:
  port: 8001

spring:
  application:
    name: cloud-payment-service

  datasource:
    type: com.alibaba.druid.pool.DruidDataSource            # 当前数据源操作类型
    driver-class-name: org.gjt.mm.mysql.Driver              # mysql驱动包
    url: jdbc:mysql://localhost:3306/springclouddemo?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: 123456

eureka:
  client:
    #表示是否将自己注册进EurekaServer默认为true。
    register-with-eureka: true
    #是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
    fetchRegistry: true
    service-url:
      #单机版
      #defaultZone: http://localhost:7001/eureka
      defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka

  instance:
    instance-id: payment8001
    #访问路径可以显示IP地址
    prefer-ip-address: true


mybatis:
  mapperLocations: classpath:mapper/*.xml
  type-aliases-package: com.badao.springclouddemo.entities    # 所有Entity别名类所在包
复制代码

3、这时可以看到主机名以指定的instance-id进行显示,并且悬浮时左下角有Ip地址提示。

 

posted on   霸道流氓  阅读(166)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结
历史上的今天:
2021-05-12 CentOS中怎样卸载旧版本Git并安装高版本Git
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示