简介
集中式的、动态的配置管理设施,配置服务器为各个不同微服务应用的所有环境提供了一个中心化的外部配置。
功能
-
集中管理配置文件
-
不同环境不同配置,动态化的配置更新
-
服务向配置中心统一拉取配置
-
配置变动时,服务无需重启即可刷新
-
配置信息以rest接口的形式暴露
Config服务端配置
- yml配置
server:
port: 3344
spring:
application:
name: cloud-config-center
cloud:
config:
server:
git:
uri: 填写你自己的github路径
search-paths:
- springcloud-config
label: master
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka
-
主启动类加@EnableConfigServer
-
访问http://localhost:3344/master/config-dev.yml测试
配置读取规则:/{label}/{application}-{profile}.yml对应分支-服务名-环境
Config客户端配置
- bootstrap.yml—系统级别,优先级更高,默认不会被本地属性覆盖。
server:
port: 3355
spring:
application:
name: config-client
cloud:
config:
label: master
name: config
profile: dev
uri: http://localhost:3344
eureka:
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka
-
业务类用@Value即可注入从中心取得的配置
-
测试:http://localhost:3355/configInfo
动态刷新 修改客户端
-
pom引入actuator配置
-
修改yml
management:
endpoints:
web:
exposure:
include: "*"
-
controller类加@RefreshScope
-
发送post请求curl -X POST "http://localhost:3355/actuator/refresh"刷新