一、概述

参看地址:https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_environment_repository

例如:git、svn、基于git本地存储、 本地存储、Vault

二、git

  EnvironmentRepository的默认实现使用Git后端。要更改存储库的位置,可以在配置服务器中设置“spring.cloud.config.server.git.uri”配置属性(例如,在application.yml中)。

优点:版本审计、分布式简单

准备工作

1、新建两个git:

  sample:https://github.com/bjlhx15/spring-cloud-config-test-sample.git

  special:https://github.com/bjlhx15/spring-cloud-config-test-special.git

2、克隆到本地

  在每个仓库中增加application.yml,内容如下:

  sample中的配置:

profile: sample

  special中的配置:

profile: special

  然后提交git。

2.1、Git URI中的占位符

2.1.1、开发

  代码:https://github.com/bjlhx15/spring-cloud/tree/master/config-part/microservice-config-server

  修改配置文件:【注意uri中的通配符{application}】

server:
port:
spring:
cloud:
config:
server:
git:
uri: https://github.com/bjlhx15/{application}

2.1.1、访问

  http://localhost:8080/spring-cloud-config-test-sample-default.yml

  http://localhost:8080/spring-cloud-config-test-special-default.yml

  可以发现,不同微服务对应不同git配置服务,配置隔离。

2.2、模式匹配和多个存储库

  还有对应用程序和配置文件名称进行模式匹配的更复杂要求的支持。模式格式是带有通配符的{application} / {profile}名称的逗号分隔列表(其中可能需要引用以通配符开头的模式)。例:

在准备工作的special中添加开发【spring-cloud-config-test-special-dev.yml】和测试环境【spring-cloud-config-test-special-test.yml】

内容分别如下:

  spring-cloud-config-test-special-dev.yml

profile: special-dev

  spring-cloud-config-test-special-test.yml

profile: special-test

2.2.1、开发

  代码:https://github.com/bjlhx15/spring-cloud/tree/master/config-part/microservice-config-server

  修改配置文件: 

server:
port:
spring:
cloud:
config:
server:
git:
uri: https://github.com/bjlhx15/spring-cloud-config-test-repo #公用的
repos:
simple: https://github.com/bjlhx15/spring-cloud-config-test-sample
special:
pattern: special*/dev*,*special*/test*
uri: https://github.com/bjlhx15/spring-cloud-config-test-special

  实际测试出错,正在排查中

Binding to target org.springframework.cloud.config.server.ssh.SshUriProperties(uri=https://github.com/bjlhx15/spring-cloud-config-test-repo hostKeyAlgorithm=null, hostKey=null, privateKey=null, ignoreLocalSshSettings=false, knownHostsFile=null, preferredAuthentications=null, strictHostKeyChecking=true,){repos={special=org.springframework.cloud.config.server.ssh.SshUriProperties(uri=https://github.com/bjlhx15/spring-cloud-config-test-special hostKeyAlgorithm=null, hostKey=null, privateKey=null, ignoreLocalSshSettings=false, knownHostsFile=null, preferredAuthentications=null, strictHostKeyChecking=true,)}} failed:

    Property: spring.cloud.config.server.git.repos[sample]
Value: https://github.com/bjlhx15/spring-cloud-config-test-sample
Reason: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.cloud.config.server.ssh.SshUriProperties$SshUriNestedRepoProperties' for property 'repos[sample]'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.cloud.config.server.ssh.SshUriProperties$SshUriNestedRepoProperties' for property 'repos[sample]': no matching editors or conversion strategy found

可以查看:org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository,中repos属性

进入org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.PatternMatchingJGitEnvironmentRepository:查看到pattern和URI

repo中的pattern属性实际上是一个数组,因此您可以在属性文件中使用YAML数组(或[0],[1]等后缀)绑定到多个模式。如果您要使用多个配置文件运行应用程序,则可能需要执行此操作。

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
repos:
development:
pattern:
- '*/development'
- '*/staging'
uri: https://github.com/development/config-repo
staging:
pattern:
- '*/qa'
- '*/production'
uri: https://github.com/staging/config-repo

2.3、searchPaths

  每个存储库还可以选择将配置文件存储在子目录中,并且可以将搜索这些目录的模式指定为searchPaths。例如在顶层:

server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://github.com/bjlhx15/spring-cloud-config-test-repo
searchPaths:
- foo # foo 路徑
- bar # bar 路徑

  访问:

    http://localhost:8080/foo-dev.yml

    http://localhost:8080/bar-dev.yml

    http://localhost:8080/de-dev.yml

  服务器搜索顶层 “/”和foo子目录中的配置文件,以及名称以“bar”开头的任何子目录。使管理清晰一些

其实也可以使用通配符

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
searchPaths: '{application}'

2.4、cloneOnStart

查看以上代码可知,都是在调用使用时候加载配置

Adding property source: file:/C:/Users/ADMINI~1/AppData/Local/Temp/config-repo-6862549358101599484/application.yml

增加参数

spring:
cloud:
config:
server:
git:
uri: https://git/common/config-repo.git
cloneOnStart: true #全部启动时候加载
repos:
team-a:
pattern: team-a-*
cloneOnStart: true
uri: http://git/team-a/config-repo.git
team-b:
pattern: team-b-*
cloneOnStart: false
uri: http://git/team-b/config-repo.git
team-c:
pattern: team-c-*
uri: http://git/team-a/config-repo.git

三、用户授权

配置用户名密码等

server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://github.com/bjlhx15/spring-cloud-config-test-repo
username: ***
password: ***

0702-spring cloud config-git仓库配置、用户授权的更多相关文章

  1. spring cloud config svn仓库配置

    之前快速入门了一下spring cloud config 但是仓库用的别人博客上的git仓库,公司用的是svn项目管理中心,下面这个自己配置的时候出现的错误 You need to configure ...

  2. 【Spring Cloud】Spring Cloud Config 实现分布式配置中心

    Spring Cloud Config 实现分布式配置中心 一.分布式配置中心 分布式系统中,往往拥有大量的服务应用,而每个应用程序都需要有对应的配置文件来协助完成服务环境初始化.运行.因此生产了大量 ...

  3. 使用Spring Cloud Config统一管理配置,别再到处放配置文件了

    1 前言 欢迎访问南瓜慢说 www.pkslow.com获取更多精彩文章! 可配置是一个成熟软件系统应该提供的特性,而配置管理对于大型系统就显得十分重要,特别是对于拥有多个应用的微服务系统.可喜的是, ...

  4. .NET Core微服务之基于Steeltoe使用Spring Cloud Config统一管理配置

    Tip: 此篇已加入.NET Core微服务基础系列文章索引 =>  Steeltoe目录快速导航: 1. 基于Steeltoe使用Spring Cloud Eureka 2. 基于Steelt ...

  5. spring cloud config git库文件搜索顺序

    spring.cloud.config.server.git.uri只配置到仓库那一层就行了,需要访问仓库的子目录的话就配置spring.cloud.config.server.git.searchP ...

  6. Spring Cloud Config git版

    由于在学习这块内容的时候还不会使用gitHub所以就用了osc的码云 config server POM文件 <dependency> <groupId>org.springf ...

  7. spring cloud config —— git配置管理

    目录 talk is cheep, show your the code Server端 pom.xml server的application.yml 配置文件 测试Server client端 po ...

  8. 微服务SpringCloud之Spring Cloud Config配置中心Git

    微服务以单个接口为颗粒度,一个接口可能就是一个项目,如果每个项目都包含一个配置文件,一个系统可能有几十或上百个小项目组成,那配置文件也会有好多,对后续修改维护也是比较麻烦,就和前面的服务注册一样,服务 ...

  9. Spring Cloud Config(二):基于Git搭建配置中心

    1.简述 本文选用Git作为配置仓库,新建两个环境的配置文件夹,dev 和 test,文件夹中分别存放 Config Client 端的配置文件,目录结构如下: ├ ─ ─ dev └ ─ ─ con ...

  10. SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)

    一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...

随机推荐

  1. ChemDraw常用到的几种技巧

    ChemDraw对于化学学习的重要性相当于CAD和建筑学.PS和设计,所以如果你是一名生化相关的工作人员,拥有ChemDraw并掌握ChemDraw的使用方法十分必要!这是一款对于我们研究化学的人来说 ...

  2. jQuery Datatable 转载

    jQuery Datatable 实用简单实例 时间 2014-05-08 10:44:18  51CTO推荐博文 原文  http://sgyyz.blog.51cto.com/5069360/14 ...

  3. mysql数据库binary log中的事件到底是什么?

    需求描述: 最近看mysql备份恢复的时候,基于时间点恢复,提到了binary log中存的是"事件" 那么到底什么是事件呢 概念解释: binary log中存的是事件(even ...

  4. day07<面向对象+>

    面向对象(构造方法Constructor概述和格式) 面向对象(构造方法的重载及注意事项) 面向对象(给成员变量赋值的两种方式的区别) 面向对象(学生类的代码及测试) 面向对象(手机类的代码及测试) ...

  5. Java类的设计----多态性及其应用

    多态性及其应用 多态性 多态—在Java中,子类的对象可以替代父类的对象使用一个变量只能有一种确定的数据类型一个引用类型变量可能指向(引用)多种不同类型的对象 Person p = new Stude ...

  6. 关于直播学习笔记-004-nginx-rtmp、srs、vlc、obs

    1.采集端:OBS RTMP推流地址:rtmp://192.168.198.21:1935/live 流密钥:livestream(任意-但播放地址与此一致) 2.播放端:nginx-rtmp-win ...

  7. m2014-architecture-imgserver->Lighttpd Mod_Cache很简单很强大的动态缓存

    Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全.快速.兼容性好并且灵活的web server环境.具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模 ...

  8. linux文件锁flock【转】

    转自: https://www.cnblogs.com/kex1n/p/7100107.html linux文件锁flock   在多个进程同时操作同一份文件的过程中,很容易导致文件中的数据混乱,需要 ...

  9. poj_3067 树状数组

    题目大意 左右两个竖排,左边竖排有N个点,从上到下依次标记为1,2,...N; 右边竖排有M个点,从上到下依次标记为1,2....M.现在从K条直线分别连接左边一个点和右边一个点,求这K条直线的交点个 ...

  10. LeetCode——Best Time to Buy and Sell Stock III

    Description: Say you have an array for which the ith element is the price of a given stock on day i. ...