spring 云配置搜索路径
spring cloud config searchPaths
我正在考虑通过 Spring Cloud Config 实施 12 因素方法来外部化配置,但我无法像我预期的那样使用 searchPaths 使通配符工作。
文档 http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_server 提到可以在 searchPaths 变量中使用通配符 {application}、{label}、{profile},这样 "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)."
我希望有一个 git 存储库,每个配置文件都有子目录(然后是每个应用程序),或者每个应用程序有子目录(然后是配置文件)。
例如
spring:
cloud:
config:
server:
git:
uri: https://stash.xxx.com.au/scm/xxx/config
searchPaths: {application}
or
searchPaths: {profile}
or
searchPaths: {application}/{profile}
然而,当我在搜索路径中使用任何通配符 {application} 或 {profile} 时,它在 git 存储库中找不到数据,或者连接选项根本无法启动。
有没有人有我可以参考的工作示例?
干杯
罗伊
实际上,用户指南中的 none 个示例显示了 searchPaths
列表中使用的模式。我认为 GIT 后端不支持该功能(但 {application}
实际上是文件系统后端的默认设置,即在 "native" 配置文件中工作的那个)。
使用单引号,效果很好。
searchPaths: '{application}'
希望这对遇到此问题的人有所帮助。
除上述之外,更重要的是,如果您希望读取在每个环境的多个应用程序之间共享的通用配置(例如 application.yml)。然后将 application.yml 放在一个文件夹中(比如 - common),然后配置如下:
searchPaths:
- '{application}'
- common
{application} 在配置客户端的 bootstrap.yaml.
中解析为 'spring.application.name' 的值
我认为它可能对 post 我们的配置有用,因为它展示了多个搜索路径的优先顺序。本机后端 search-order
属性 有很好的文档记录,但我不清楚 git 后端 search-paths
的工作方式相同。
这是 Spring 云发布系列 2020.0.2:
spring:
cloud:
config:
server:
git:
uri: /path/to/git/repo
search-paths:
- /defaults
- "env_{profile}"
稍后找到的属性 search-paths 覆盖较早找到的属性。
使用示例:
- 对于
defaults/application.yml
中的所有服务和环境,我们默认 SQL logging = true。所以它在 TEST、QA 和 UAT 中有效。
- 我们可以在
defaults/specific_app_name.yml
中覆盖特定应用程序的默认值(我们不用于 SQL 日志记录)。
- 在生产环境中,我们在
env_prod/application.yml
. 中关闭所有 SQL 日志记录
- 如果需要,我们可以通过将 属性 添加到
env_prod/specific_app_name.yml
. 来为单个生产服务启用 SQL 登录
(编辑:我最初 posted 4 search-paths 以上,但我意识到这个例子不需要最后两个,事实上我们在实践中从来不需要它们所以就在我们说话的时候,我正在从我们的代码中删除它们。)
我正在考虑通过 Spring Cloud Config 实施 12 因素方法来外部化配置,但我无法像我预期的那样使用 searchPaths 使通配符工作。
文档 http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_server 提到可以在 searchPaths 变量中使用通配符 {application}、{label}、{profile},这样 "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)."
我希望有一个 git 存储库,每个配置文件都有子目录(然后是每个应用程序),或者每个应用程序有子目录(然后是配置文件)。
例如
spring:
cloud:
config:
server:
git:
uri: https://stash.xxx.com.au/scm/xxx/config
searchPaths: {application}
or
searchPaths: {profile}
or
searchPaths: {application}/{profile}
然而,当我在搜索路径中使用任何通配符 {application} 或 {profile} 时,它在 git 存储库中找不到数据,或者连接选项根本无法启动。
有没有人有我可以参考的工作示例? 干杯 罗伊
实际上,用户指南中的 none 个示例显示了 searchPaths
列表中使用的模式。我认为 GIT 后端不支持该功能(但 {application}
实际上是文件系统后端的默认设置,即在 "native" 配置文件中工作的那个)。
使用单引号,效果很好。
searchPaths: '{application}'
希望这对遇到此问题的人有所帮助。
除上述之外,更重要的是,如果您希望读取在每个环境的多个应用程序之间共享的通用配置(例如 application.yml)。然后将 application.yml 放在一个文件夹中(比如 - common),然后配置如下:
searchPaths:
- '{application}'
- common
{application} 在配置客户端的 bootstrap.yaml.
中解析为 'spring.application.name' 的值我认为它可能对 post 我们的配置有用,因为它展示了多个搜索路径的优先顺序。本机后端 search-order
属性 有很好的文档记录,但我不清楚 git 后端 search-paths
的工作方式相同。
这是 Spring 云发布系列 2020.0.2:
spring:
cloud:
config:
server:
git:
uri: /path/to/git/repo
search-paths:
- /defaults
- "env_{profile}"
稍后找到的属性 search-paths 覆盖较早找到的属性。
使用示例:
- 对于
defaults/application.yml
中的所有服务和环境,我们默认 SQL logging = true。所以它在 TEST、QA 和 UAT 中有效。 - 我们可以在
defaults/specific_app_name.yml
中覆盖特定应用程序的默认值(我们不用于 SQL 日志记录)。 - 在生产环境中,我们在
env_prod/application.yml
. 中关闭所有 SQL 日志记录
- 如果需要,我们可以通过将 属性 添加到
env_prod/specific_app_name.yml
. 来为单个生产服务启用 SQL 登录
(编辑:我最初 posted 4 search-paths 以上,但我意识到这个例子不需要最后两个,事实上我们在实践中从来不需要它们所以就在我们说话的时候,我正在从我们的代码中删除它们。)