consul与springcloud整合
application.yml中配置如下:
# 配置中心配置 spring: application: name: device-api cloud: consul: host: consul port: 8500 config: acl-token: c6a05ce4-ef63-8dcb-d120-8caa45d9edd8 enabled: true data-key: data prefix: config format: yaml profile-separator: ',' discovery: acl-token: c6a05ce4-ef63-8dcb-d120-8caa45d9edd8 # 启用服务发现 enabled: true # 启用服务注册 register: true # 服务停止时取消注册 deregister: true service-name: ${spring.application.name} # 表示注册时使用IP而不是hostname prefer-ip-address: true # 执行监控检查的频率 health-check-interval: 30s # 设置健康检查失败多长时间后,取消注册 health-check-critical-timeout: 30s # 健康检查的路径 health-check-path: /actuator/info # 服务注册标识,格式为:应用名称+服务器IP+端口 instance-id: ${spring.application.name}:${spring.cloud.client.ip-address}:${server.port}
参数描述:
health-check-path: /actuator/info 表示为健康检查的url health-check-interval: 30s 表示健康检查的时间间隔
instance-id: device-api-192-168-0-48 表示为consul service列表中的service id format: YAML 表示consul中的key-value的value内容,采用YAML格式
prefix: config 表示consul用于存储配置的文件夹根目录名为config
profile-separator: ',' 表示如果有多个profile,profile与defaultContext之间用什么分隔符来表示 data-key: data 表示最后一层节点的key值名称,一般默认为data
需要创建一个test环境的配置,则key名可以取为:
config/application,test/data
业务需求变更永无休止,技术前进就永无止境!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 25岁的心里话