服务注册中心 Eureka actuator微服务信息完善
现在存在的问题是,服务提供者没有具体的IP地址,在实际生产中,集群是不同的服务器不同的端口提供服务,所以注册中心需要知道具体的提供者的IP和端口和服务名称。
1.服务名称修改
在8001和8002的yml中修改配置:
server:
port: 8001
spring:
application:
name: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: org.gjt.mm.mysql.Driver
url: jdbc:mysql://localhost:3306/standarddb?userUnicode=true&characterEncoding=utf-8&useSSL=false
username: sa
password: HRBJYKJ-Battery
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.atguigu.springcloud.entities
eureka:
client:
#表示是否将自己注册进EurekaServer,默认true
register-with-eureka: true
#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置true才能配合ribbon使用负载均衡。
fetch-registry: true
service-url:
defaultZone: http://eurreka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版
#主机名实例
instance:
instance-id: paymet8001
修改8002的yml配置:
server: port: 8002 spring: application: name: cloud-payment-service datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://localhost:3306/standarddb?userUnicode=true&characterEncoding=utf-8&useSSL=false username: sa password: HRBJYKJ-Battery mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.atguigu.springcloud.entities eureka: client: #表示是否将自己注册进EurekaServer,默认true register-with-eureka: true #是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置true才能配合ribbon使用负载均衡。 fetch-registry: true service-url: defaultZone: http://eurreka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版 #主机名实例 instance: instance-id: paymet8002
查看修改后的结果:
实例名称好处是可根据具体提供的业务定义微服务名称。也可按照公司规定的规则名命,一目了然。
2.访问信息有IP信息提示
修改8001和8002yml配置:
server: port: 8001 spring: application: name: cloud-payment-service datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://localhost:3306/standarddb?userUnicode=true&characterEncoding=utf-8&useSSL=false username: sa password: HRBJYKJ-Battery mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.atguigu.springcloud.entities eureka: client: #表示是否将自己注册进EurekaServer,默认true register-with-eureka: true #是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置true才能配合ribbon使用负载均衡。 fetch-registry: true service-url: defaultZone: http://eurreka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版 #主机名实例 instance: instance-id: paymet8001 prefer-ip-address: true #访问路径可以显示IP地址
查看结果:
分类:
SpringCloud
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!