简体   繁体   English

从 Spring-Boot 访问 yaml consul 配置

[英]Reaching yaml consul config from Spring-Boot

I try to use Consul as configuration server with Spring boot.我尝试使用 Consul 作为 Spring Boot 的配置服务器。 I already succeed to use the kv store of consul to fetch variables, but now I want to be able to fetch variables as YAML files.我已经成功地使用 consul 的 kv 存储来获取变量,但现在我希望能够将变量作为 YAML 文件获取。 Here is my bootstrap.yaml :这是我的 bootstrap.yaml :

spring:
  cloud.consul:
    host: localhost
    port: 8500
    config:
      enabled: true
      format: YAML
      failFast: true

I put this config on consul on the path "/config/my.application.name/data" :我将此配置放在 consul 的路径 "/config/my.application.name/data" 上:

testspring: hello

And I try to reach this property using :我尝试使用以下方法访问此属性:

@Value("${testspring}")

... with no success. ......没有成功。 What am I missing here ?我在这里错过了什么? What is the good path for config on consul ?在 consul 上配置的好方法是什么?

Thanks谢谢

EDIT : It appears that the config is loaded on the value ${data} and that it is not parsed.编辑:似乎配置加载在值 ${data} 上并且没有被解析。 The data="testspring: hello", which is not what is expected. data="testspring: hello",这不是预期的。

I was able to fetch data using your sample.我能够使用您的示例获取数据。 But if I remove format: YAML (so use default KEY_VALUE) from my config then not parsed data property is fetched.但是如果我从我的配置中删除format: YAML (所以使用默认的 KEY_VALUE)然后未解析的data属性被获取。 Maybe double check your bootstrap.yml config for correct indentations.也许仔细检查您的bootstrap.yml配置以获取正确的缩进。

What version of Spring Boot and Spring Cloud you are using ?您使用的是哪个版本的 Spring Boot 和 Spring Cloud?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM