Consul 提供用于存储配置和其他元数据的 Key/Value 存储。Spring Cloud Consul 配置是配置服务器和客户端的替代方案。在特殊的 "bootstrap" 阶段,配置被加载到 Spring 环境中。默认情况下,配置存储在 config/testApp,dev/ config/testApp/ config/application,dev/ config/application/
最具体的属性源位于顶部,而最不具体的属性源位于底部。
当前在应用程序启动时读取配置。向
要开始使用 consul 配置,请使用带有 group 这将启用将设置 Spring Cloud Consul 配置的自动配置。 Consul 配置可以使用以下属性进行自定义: bootstrap.yml. spring: cloud: consul: config: enabled: true prefix: configuration defaultContext: apps profileSeparator: '::'
Consul 配置观察利用 consul 监视键前缀的能力。配置观察进行一个阻塞的 Consul HTTP API 调用,以确定当前应用程序的任何相关配置数据是否已更改。如果有新的配置数据,将发布刷新事件。这相当于调用
更改配置表被称为更改
要禁用配置观察,请设置
观察使用 Spring
与单独的 键/值 对相比,以 YAML 或 Properties 格式存储一个属性块可能更方便。将 bootstrap.yml. spring: cloud: consul: config: format: YAML
YAML 必须在 consul 中的相应 config/testApp,dev/data config/testApp/data config/application,dev/data config/application/data 你可以将 YAML 文档存储在上面列出的任何键中。
你可以使用
git2consul 是一个 Consul 社区项目,它将文件从 git 存储库加载到 Consul 中的各个键。默认情况下,键的名称是文件的名称。支持 YAML 和 Properties 文件,文件扩展名分别为 bootstrap.yml. spring: cloud: consul: config: format: FILES
给定 .gitignore application.yml bar.properties foo-development.properties foo-production.yml foo.properties master.ref 将创建以下属性源: config/foo-development.properties config/foo.properties config/application.yml 每个键的值必须是格式正确的 YAML 或 Properties 文件。 |