如何使用Spring cloud zookeeper配置读取子节点

问题描述 投票:0回答:2

我无法通过使用Spring Cloud Zookeeper配置读取应用程序的子节点。

[为简单起见,假设我已将其命名为Myapplication,并在Zookeeper中的config(/ config / Myapplication)下创建了相同的名称节点。我在节点内创建了一个属性,例如(/ config / Myapplication / sample 1)。因此,“示例”属性可以访问我的应用程序。

但是,如果我在Myapplication(/ config / Myapplication / Configuration config)下有一个子节点。现在,我需要在未发生的“配置”节点下访问“ config”属性。

我尝试通过我的应用程序中的以下代码访问,但是没有运气:-

@Value("${Configuration/config: Default Child Node config}")
    private String config;

请提出一些从此处前进的方法。

spring spring-boot spring-cloud spring-cloud-config
2个回答
0
投票

@ Value(“ $ {Configuration.config:默认子节点配置}”)私有字符串配置;


0
投票

简而言之,如果您这样定义节点:

/config/<Your-App-Name>/consumerId 12345

您应该能够像这样访问它:

@Value(${consumerId})
private String consumeId

注意。-您只能按以下方式定义变量:

/config/<Your-App-Name>/youVar1 val1
/config/<Your-App-Name>/youVar2 val2 ...etc

定义为/ config /的子节点的节点可以通过springboot轻松访问。

更多技术细节here

© www.soinside.com 2019 - 2024. All rights reserved.