java 整合 consul_SpringBoot集成Consul服务接入配置中心

闲话少谈,直奔主题

一、我的研发环境

springboot:2.1.8.RELEASE

spring.cloud:Greenwich.SR5

二、POM文件展示

4.0.0

org.springframework.boot

spring-boot-starter-parent

2.1.8.RELEASE

....

....

....

1.8

2.1.8.RELEASE

Greenwich.SR5

UTF-8

org.springframework.boot

spring-boot-starter-parent

${spring.boot.version}

pom

import

org.springframework.cloud

spring-cloud-dependencies

${spring.cloud.version}

pom

import

org.springframework.cloud

spring-cloud-starter-consul-discovery

org.springframework.cloud

spring-cloud-starter-consul-config

org.springframework.boot

spring-boot-starter-actuator

org.springframework.boot

spring-boot-maven-plugin

三、bootstrap.yaml文件的编写。(经过验证,配置中心默认加载bootstrap.(yml|yaml|properties)配置文件,完成配置中心功能的初始化)

# consul的配置启动环境

consul:

host: 192.168.10.118 # 注册地址( need )

port: 8501 # Consul 端口( need )

acl-token: 495af318-0822-b701-ee8d-80dc6d4d863a # 访问token ( need )

spring:

#consul配置

cloud:

# Spring Cloud Consul 通用配置项,对应 ConsulProperties 类

consul:

host: ${consul.host} # 注册地址

port: ${consul.port} # Consul 端口

# consul配置中心

config:

prefix: config

enabled: true

format: YAML

data-key: common

acl-token: ${consul.acl-token}

# Spring Cloud Consul Discovery 配置项,对应 ConsulDiscoveryProperties 类

discovery:

enabled: true

# register: true # 注册自身到consul

deregister: true # 服务停止时取消注册

service-name: ${spring.application.name} # 注册到 Consul 的服务名,默认为 `spring.application.name` 配置项

health-check-path: /actuator/health # 健康检查的接口,默认为 /actuator/health,由 Spring Boot Actuator 提供

acl-token: ${consul.acl-token}

四、consul的系统参数配置

我的测试地址:http://192.168.10.118:8500/ui/rdc/kv/config/app-exchange-api/common/edit

20201112011524204ecp9xz4fj5uqzmy_0.png

五、配置完成,系统启动成功读取配置......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值