闲话少谈,直奔主题
一、我的研发环境
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
五、配置完成,系统启动成功读取配置......