java - 如何从不同的 Consul 上下文中获取多个 Consul KV?
问题描述
我在 Consul 上有这些 KV 源存储:
config/books/<key>
config/common/<key>
在我的 Spring Boot 应用程序 application.yml 中,我将其配置如下:
spring:
application:
name: sampleapp
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
prefix: config
defaultContext: books
我知道我所做的此配置已将应用程序指向从config/books读取。
但我不知道如何从config/common和config/books中检索 Consul KV 配置。
解决方案
那里不是很灵活,但是如果您重命名项目并使用 defaultContext 也可以做到。根据文档Spring Cloud Consul Config 采用以下路径:
config/testApp,dev/
config/testApp/
config/application,dev/
config/application/
其中testApp - 您的应用程序的名称,应用程序- 默认上下文
因此,使用以下配置它将起作用
spring:
application:
name: books
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
prefix: config
defaultContext: common
运行此配置后的日志:
Located property source: CompositePropertySource {name='consul', propertySources=[ConsulPropertySource {name='config/books/'}, ConsulPropertySource {name='config/common/'}]}
推荐阅读
- javascript - Expo (web) 找到应用程序数据文件,但 Expo (android) 没有
- java - 了解 Hazelcast 中的这些指标名称的含义
- node.js - 在 Cognito 中链接第三方应用程序帐户
- android - Branch.io 是否在 expo 托管工作流中工作?
- html - 验证到
- python - 使用beautifulsoup绕过python中的错误520
- javascript - 使用 Javascript 在页面退出时显示弹出模式
- python - 如何正确更新 django 模型?
- python - Pandas Python如何获取除包含总和的行之外的所有其他行的总和
- python - Python NameError:名称“”未定义