[英]Shared config possible using Spring cloud consul config?
We're using Spring Cloud Consul Config 1.3-RELEASE on Java 8 for simple app helloworldclient, works as expected with bootstrap.xml
... 我们正在Java 8上使用Spring Cloud Consul Config 1.3-RELEASE来实现简单的应用helloworldclient,可与
bootstrap.xml
一起正常工作...
spring:
cloud:
consul:
token: xxxx-xxxx-xxxx-xxxx
discovery:
enabled: true
register: true
service-name: helloworldclient-xyz123
health-check-url: ${HEALTH_CHECK_URL}
config:
profile-separator: '/'
enabled: true
format: yaml
host: ${CONSUL_HTTP_ADDR}
port: 8500
application:
name: helloworldclient
Running the app with profile dev
, this is the loaded config from /env
... 使用profile
dev
运行应用程序,这是从/env
加载的配置。
"consul:config/helloworldclient/dev/": {
"product[0].sku": "BL394D",
"product[0].quantity": 8
}
All that is fine, but we're not sure why the remaining consul config sections are even present, and what they're used for: 一切都很好,但是我们不确定为什么剩下的领事配置部分仍然存在,以及它们的用途是:
"consul:config/application/dev/": {},
"consul:config/application/": {},
This is interesting because we have a requirement for shared config such that multiple applications have a way load common, environment-specific config from consul, if possible; 这很有趣,因为我们需要共享配置,以便多个应用程序有可能从领事中加载通用的,特定于环境的配置; some questions to determine if this is a viable solution:
一些问题,以确定这是否是可行的解决方案:
Questions 问题
config/application
configurable such that on startup the app reads from config/mysharedconfig
instead? config/application
配置,以便在启动时,应用程序改为从config/mysharedconfig
读取? /config/application/dev
as a shared config location where multiple applications can load common, environment-specific config? /config/application/dev
用作共享配置位置,多个应用程序可以在其中共享特定于环境的通用配置? I'm answering my own question: 我在回答自己的问题:
Based on documentation -- and some quick tests -- Consul supports shared properties via spring.cloud.consul.config.defaultContext
, which by default is set to application
, effectively loading config from consul:config/application
, consul:config/application/dev
, etc., on startup (in addition to config for the app, of course). 基于文档 -和一些快速测试
spring.cloud.consul.config.defaultContext
通过spring.cloud.consul.config.defaultContext
支持共享属性,该属性默认设置为application
,有效地从consul:config/application
, consul:config/application/dev
加载配置consul:config/application/dev
等,在启动时(当然,除了应用程序的配置外)。 And defaultContext
is customizable, so we changed it to commoncfg
then granted all ACL tokens permission to read from that location. 而且
defaultContext
是可自定义的,因此我们将其更改为commoncfg
然后授予了所有ACL令牌读取该位置的权限。 You don't need to bother with ACL tokens unless you're using them, I only mention it because we use tokens and this step was necessary. 除非您正在使用ACL令牌,否则您无需操心,我只提到它是因为我们使用令牌,并且此步骤是必要的。
spring: cloud: consul: config: defaultContext: commoncfg 春天:云:领事:配置:默认上下文:commoncfg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.