Oleksandr Gavenko's blog
2019-04-23 01:00 Spring Cloud Config searchPaths and Git repository layout

Spring Cloud Config Server has magical property searchPaths that magically alter search order of YAML file in Git repository. YAML file name conventions and config file layout itself are magic.

Request syntax:

GET /{application}/{profile}[/{label}]
GET /{application}-{profile}.yml
GET /{label}/{application}-{profile}.yml
GET /{application}-{profile}.properties
GET /{label}/{application}-{profile}.properties

Storage layout.

With altered searchPaths in bootstrap.yaml:

spring:
  cloud:
    config:
      server:
        git:
          searchPaths: "{application}"

for hierarchy:

bash# tree
├── application.yaml
├── application-dev.yaml
├── my.yaml
├── my-dev.yaml
├── my
│   ├── application.yaml
│   ├── application-dev.yaml
│   ├── my.yaml
│   └── my-dev.yaml

on request http://localhost:8888/unknown/default Config Server returns:

propertySources.1.name: file://c:/home/devel/config/application.yaml

for http://localhost:8888/unknown/dev returns:

propertySources.1.name: file://c:/home/devel/config/application-dev.yaml
propertySources.2.name: file://c:/home/devel/config/application.yaml

for http://localhost:8888/my/default returns:

propertySources.1.name: file://c:/home/devel/config/my/my.yaml
propertySources.2.name: file://c:/home/devel/config/my/application.yaml
propertySources.3.name: file://c:/home/devel/config/my.yaml
propertySources.4.name: file://c:/home/devel/config/application.yaml

for http://localhost:8888/my/dev returns:

propertySources.1.name: file://c:/home/devel/config/my/my-dev.yaml
propertySources.2.name: file://c:/home/devel/config/my/application-dev.yaml
propertySources.3.name: file://c:/home/devel/config/my-dev.yaml
propertySources.4.name: file://c:/home/devel/config/application-dev.yaml
propertySources.5.name: file://c:/home/devel/config/my/my.yaml
propertySources.6.name: file://c:/home/devel/config/my/application.yaml
propertySources.7.name: file://c:/home/devel/config/my.yaml
propertySources.8.name: file://c:/home/devel/config/application.yaml

With altered searchPaths to:

spring:
  cloud:
    config:
      server:
        git:
          searchPaths:
            - "{application}"
            - "."

for http://localhost:8888/my/dev Spring Cloud Server returns:

propertySources.1.name: file://c:/home/devel/config/my-dev.yaml
propertySources.2.name: file://c:/home/devel/config/application-dev.yaml
propertySources.3.name: file://c:/home/devel/config/my/my-dev.yaml
propertySources.4.name: file://c:/home/devel/config/my/application-dev.yaml
propertySources.5.name: file://c:/home/devel/config/my.yaml
propertySources.6.name: file://c:/home/devel/config/application.yaml
propertySources.7.name: file://c:/home/devel/config/my/my.yaml
propertySources.8.name: file://c:/home/devel/config/my/application.yaml

With altered searchPaths to:

spring:
  cloud:
    config:
      server:
        git:
          searchPaths:
            - "."
            - "{application}"

for http://localhost:8888/my/dev Spring Cloud Server returns:

propertySources.1.name: file://c:/home/devel/config/my/my-dev.yaml
propertySources.2.name: file://c:/home/devel/config/my/application-dev.yaml
propertySources.3.name: file://c:/home/devel/config/my-dev.yaml
propertySources.4.name: file://c:/home/devel/config/application-dev.yaml
propertySources.5.name: file://c:/home/devel/config/my/my.yaml
propertySources.6.name: file://c:/home/devel/config/my/application.yaml
propertySources.7.name: file://c:/home/devel/config/my.yaml
propertySources.8.name: file://c:/home/devel/config/application.yaml

Test file looks like (can help inspecting priority of config order):

find . -name .git -prune -o -type f -print | while read f; do echo $f; cat $f; done

./application-dev.yaml
prop: application-dev
./application.yaml
prop: application-default
./my/application-dev.yaml
prop: my/application-dev
./my/application.yaml
prop: my/application-default
./my/my-dev.yaml
prop: my/my-dev
./my/my.yaml
prop: my/my-default
./my-dev.yaml
prop: my-dev
./my.yaml
prop: my-default
java, spring, git

Feeds

all / emacs / java

Tags

adb(1), admin(1), android(1), anki(1), ansible(2), aop(1), blog(2), bytecode(1), c(1), css(2), cygwin(2), driver(1), emacs(3), fs(1), git(3), google(1), gradle(1), hardware(1), hg(2), html(1), interview(13), java(4), js(3), lang(2), lighttpd(1), markdown(1), mobile(1), naming(1), oracle(1), print(1), problem(5), python(1), quiz(6), rst(2), security(3), spring(2), sql(2), srs(1), style(1), tls(2), txt(1), unit(1), utils(1), vcs(3), web(2), win(2), windows(1)

Archive