spring cloud config searchPaths

送分小仙女□ 提交于 2021-02-10 23:39:37

问题


I'm looking at implementing the 12factor approach to externalising config via Spring Cloud Config but am not able to get the wildcards working using searchPaths as I expected.

The documentation http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_server mentions that wildcards {application}, {label}, {profile} can be used within the searchPaths variable so that "you can segregate the directories in the path, and choose a strategy that makes sense for you (e.g. sub-directory per application, or sub-directory per profile)."

I'm looking to have a single git repo, with either subdirectories per profile (and then per app, or subdirectory per app (then by profile).

e.g.

    spring:
      cloud:
        config:
          server:
            git:
              uri: https://stash.xxx.com.au/scm/xxx/config
              searchPaths: {application}
or
              searchPaths: {profile}
or
              searchPaths: {application}/{profile}

However when I use any of the wildcards {application} or {profile} in my searchPaths it doesn't find the data in the git repo, or for the concatenated option fails to startup at all.

Does anyone have a working example of this I can refer to? Cheers Roy


回答1:


Actually none of the examples in the user guide show the pattern being used in a list of searchPaths. I don't think that feature is supported with the GIT backend (but {application} is effectively the default in the filesystem backend, i.e. the one that works in the "native" profile).




回答2:


Use single quote and it works fine.

searchPaths: '{application}'

Hope this helps if someone stumbles across this problem.




回答3:


In addition to above, and more importantly if you want your common configuration (e.g. application.yml) which is shared across multiple applications per environment, to be read. Then place application.yml in a folder (say - common), then the config goes like this:

searchPaths:
  - '{application}'
  - common

{application} resolves to the value of 'spring.application.name' in the config clients' bootstrap.yaml.

Reference: https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html#_placeholders_in_git_search_paths



来源:https://stackoverflow.com/questions/35026446/spring-cloud-config-searchpaths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!