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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值