一 代码位置
https://github.com/cakin24/spring-cloud-code/tree/master/ch12-4
二 脚本
{
"label" : "master",
"profile" : "prod",
"source" : {
"cn" : {
"springcloud" : {
"book" : {
"config" : "I am the mongdb configuration file from dev environment. I will edit."
}
}
}
}
}
插入数据库后的效果
三 测试
1 启动config-server-mongodb
2 启动config-client-mongodb
3 浏览器输入: http://localhost:9097/configConsumer/getConfigInfo
客户端配置为:
spring:
cloud:
config:
label: master
uri: http://localhost:9090
name: config
profile: prod
整个匹配过程是:先根据name找到Mongo中对应的文档config,然后依据label和profile找到对应的文档,最后读取到具体配置cn.springcloud.book.config