Config-Server针对于Git的各种配置(补)

一、模式匹配

1、准备工作

github仓库三个

(1)git@github.com:wangchunself/ymlforconfig.git

这个仓库只有默认的application.yml

(2)git@github.com:wangchunself/simple.git

这个仓库只有默认的application.yml

(3)git@github.com:wangchunself/special.git

这个仓库有application.yml,有special-test.yml,有special-fault.yml

2、application.yml配置如下:

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: git@github.com:wangchunself/ymlforconfig.git
          repos:
            simple: git@github.com:wangchunself/simple.git
            special:
              pattern: special*/dev*,special*/test*
              uri: git@github.com:wangchunself/special.git

3、测试

(1)访问http://localhost:8080/master/simple-test.yml

进入simple.git仓库,拿到application.yml这个配置文件

(2)访问http://localhost:8080/master/special-test.yml

进入special仓库,拿到special-test.yml文件

(3)访问http://localhost:8080/master/special-dev.yml

首先,因为pattern匹配,那么进入special仓库,在仓库中没找到special-dev文件,那么返回special的application.yml配置文件

(4)访问http://localhost:8080/master/special-fault.yml

在pattern中进行匹配,发现不匹配,那么立刻降级,进入ymlforconfig.git中拿到它的application.yml

 

二、searchPaths

1、准备工作

github仓库一个:git@github.com:wangchunself/ymlforconfig.git

仓库中有文件application.yml,有文件夹foo里面有文件foo-dev.yml

2、application.yml

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: git@github.com:wangchunself/ymlforconfig.git
          search-paths: foo

3、测试

(1) 访问http://localhost:8080/master/foo-dev.yml,拿到foo-dev.yml文件

(2) 访问http://localhost:8080/master/foo-test.yml,拿到application.yml文件

这个配置其实就相当于将foo文件夹里的东西,在这些请求下面相当于都在根目录下面。

searchPaths中也可以使用通配符

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: git@github.com:wangchunself/ymlforconfig.git
          searchPaths: '{application}'

三、cloneOnStart

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: git@github.com:wangchunself/ymlforconfig.git
          repos:
            simple: git@github.com:wangchunself/simple.git
            special:
              pattern: special*/dev*,special*/test*    
              uri: git@github.com:wangchunself/special.git
              cloneOnStart: false               #局部配置
          clone-on-start: true            #全局配置

这个配置的作用是,是否在ConfigServer刚启动的时候就去Git仓库抓取配置,默认是false,也就是第一次访问才去抓取

四、Github私有仓库需要配置用户名和密码

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: git@github.com:wangchunself/ymlforconfig.git
          username: XXX
          password: XXX

 

posted @ 2019-01-16 11:06  柚子味儿的西瓜  阅读(37)  评论(0)    收藏  举报