Spring Cloud Config
2017-08-23 10:41
162 查看
发博词
需要用过的人看。不是入门文档。Environment 和 PropertySource
简单点说PropertySource和Environment 的区别是,假设配置文件中有Placeholder,那么你从PropertySource中获取的值是带Placeholder的,从Environment中获取的值是替换了Placeholder之后的值;一般的实现是Environment会持有一个PropertySource的列表;
参考:
【Spring4揭秘 基础2】PropertySource和Enviroment
Spring3.1新属性管理API:PropertySource、Environment、Profile
架构
Spring Cloud Config的架构非常简单,一个Server,一个client。Server提供了多个基于HTTP协议的接口工Client调用获取信息。理解几个概念
spring cloud config label不是只指的branch,指定commitid、branch和tag的值都行,所以这些里面不要有重名的;如果配置config-server也从远程拉取信息的话,需要将configserver应用的配置都放到bootstrap.yml
下载下来的库在/tmp/config-repo-,系统的临时文件夹/config-repo-随机id,basedir可以手动指定,最好手动指定一个,临时文件夹,有些操作系统会临时清理
因为网络的原因,所有想链接到config server的客户端都需要一个bootstrap.yml文件,spring.cloud.config.uri这个文件必须要有这个配置,而我们一般是用Discovery模式,只需要指定serviceid即可
我们已经知道application-*.yml文件的优先级了,那么本地远程都有配置文件的情况下,各自的优先级是远程优先级最高,其次是本地application系列文件,bootstrap优先级最低
{application} 值是客户端的 “spring.application.name” 属性的值
{profile} 的值是 客户端的”spring.profiles.active”的值,逗号分隔
{label} 的值在configServer端设置,which is a server side feature labelling a “versioned” set of config files.
git label (commit id, branch name or tag) “/”=》(_)
Git URI可用变量:{application} and {profile} (and {label},客户端可控的变量是{application} and {profile},label是服务器端控制的,如何使用{application} and {profile}也是服务器端控制的
ConfigServer endpoint
name-profiles.properites,yml,jsonlabel/name-profile.
name/profile/label
name/profiles
label/name-profile.pyj
name/profile/label
name/profile/label
这两个接口是一个,上面这个是下面的label=null的版本,也就是label的默认值版本
/{name}-{profiles}.yml /{name}-{profiles}.yaml
/{label}/{name}-{profiles}.yml /{label}/{name}-{profiles}.yaml
label applicationname profile path resolvePlaceholders
仓库,仓库下的目录(searchPaths)
字符串匹配
label 在前面
name-profile在前面
json,yml,ymal,proprieies结尾
其实是可以控制这五个部分
public Environment(Environment env) { this(env.getName(), env.getProfiles(), env.getLabel(), env.getVersion(), env.getState()); }
要使用ConfigServer注意点
1. spring.application.name git仓库的名字要有规律,能对应起来
2. git仓库名字和配置文件所在目录也要能对应起来
使用模式
通过在url和searchpaths上使用application、profile和label,产生了下面三种常用的方式:1. all Instances in one repo
2. one repo per application
3. one repo per profile
整合Spring Cloud Bus
使用属性的地方记得加@RefreshCope注解configserver每次都刷新,不管想刷新谁
相关文章推荐
- Spring Cloud Config-Git后端
- 配置中心:Spring Cloud Config
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(二十三):配置中心(Config、Bus)
- Spring Cloud Config 之svn配置仓库与动态刷新(客户端)
- Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config
- springcloud实战之14动态刷新分布式配置中心属性配置(config)
- spring cloud:config-server中@RefreshScope的"陷阱"
- 第六篇: 分布式配置中心(Spring Cloud Config)
- 第七篇: 高可用的分布式配置中心(Spring Cloud Config)
- spring cloud/mesos:在mesos上运行spring cloud config配置服务
- springcloud(第一篇)springcloud config 入门
- Spring Cloud云服务架构 - commonservice-config配置服务搭建
- Spring Cloud Config Client 超时与重试
- spring cloud config整合gitlab搭建分布式的配置中心
- spring cloud config与bus结合
- Spring Cloud Config客户端使用
- 【SpringBoot】SpringCloud Config Server实践
- 微服务之springCloud-config-bus(十三)
- 学习微服务的统一配置管理-springCloud config+git
- spring cloud :统一管理配置文件config