Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Spring Boot访问yaml Consor配置_Spring_Spring Boot_Consul_Spring Cloud Config_Spring Cloud Consul - Fatal编程技术网

从Spring Boot访问yaml Consor配置

从Spring Boot访问yaml Consor配置,spring,spring-boot,consul,spring-cloud-config,spring-cloud-consul,Spring,Spring Boot,Consul,Spring Cloud Config,Spring Cloud Consul,我尝试使用concur作为Spring引导的配置服务器。我已经成功地使用concur的kv存储来获取变量,但现在我希望能够将变量作为YAML文件获取。这是我的引导。yaml: spring: cloud.consul: host: localhost port: 8500 config: enabled: true format: YAML failFast: true 我将此配置放在concur的路径“/config/my.ap

我尝试使用concur作为Spring引导的配置服务器。我已经成功地使用concur的kv存储来获取变量,但现在我希望能够将变量作为YAML文件获取。这是我的引导。yaml:

spring:
  cloud.consul:
    host: localhost
    port: 8500
    config:
      enabled: true
      format: YAML
      failFast: true
我将此配置放在concur的路径“/config/my.application.name/data”上:

我尝试通过以下方式访问此属性:

@Value("${testspring}")
。。。没有成功。 我错过了什么?在Consor上配置的好方法是什么

谢谢

编辑:
似乎配置是在值${data}上加载的,并且未对其进行分析。data=“testspring:hello”,这不是预期的结果。

我能够使用您的示例获取数据。但如果我从配置中删除
format:YAML
(因此使用默认的KEY\u值),则会获取未解析的
数据
属性。
可能需要再次检查您的
bootstrap.yml
config以获得正确的缩进

您正在使用哪个版本的Spring Boot和Spring Cloud

@Value("${testspring}")