Config Server的Git仓库配置详解——搜索目录

一 介绍
很多场景下,可能把配置文件放在了Git仓库子目录中,此时可以使用search-path指定,search-path同样支持占位符。
二 Config Server的application配置如下
spring:
  cloud:
    config:
      server:
        git:
          uri: http://git.oschina.net/cakin24/spring-cloud-config-repo
          search-paths: foo,bar*
logging:
  level:
    org.springframework.cloud: DEBUG
    org.springframework.boot: DEBUG
这样Config Server就会在Git仓库根目录、foo子目录、以及所有以bar开始的子目录中查找配置文件。
三 gitee截图如下
四 测试
结果为:
{
    "name": "application",
    "profiles": [
        "default"
    ],
    "label": "master",
    "version": "68a6038d4224d22fb43b62473220c6c573d80341",
    "state": null,
    "propertySources": [
        {
            "name": "http://git.oschina.net/cakin24/spring-cloud-config-repo/bar-t/application.properties",
            "source": {
                "profile": "default-bar"
            }
        },
        {
            "name": "http://git.oschina.net/cakin24/spring-cloud-config-repo/foo/application.properties",
            "source": {
                "profile": "default-foo"
            }
        },
        {
            "name": "http://git.oschina.net/cakin24/spring-cloud-config-repo/application.properties",
            "source": {
                "profile": "default",
                "test": "1"
            }
        }
    ]
}
从测试结果来看,匹配到了3个文件。

猜你喜欢

转载自blog.csdn.net/chengqiuming/article/details/80871798