【问题标题】:Spring Boot YAML ConfigSpring Boot YAML 配置
【发布时间】:2016-02-23 20:34:04
【问题描述】:

我正在尝试部署一个无法更改代码的 Spring Boot 应用程序。我更喜欢使用 YML 来配置它,但是我遇到了这个 YAML 限制:

元素有一个值或一个子元素,从不兼有。

应用程序的配置方案包括多个实例:

com.company.feature=default
com.company.feature.config=value

有什么方法可以将这些配置为 YAML,因为以下内容将是无效的:

com:
  company:
    feature: default
      config: value

【问题讨论】:

    标签: spring spring-boot yaml


    【解决方案1】:

    你不能把它全部放在一个层次结构中。其键有子项和值的任何属性都必须与值一起列出,而没有层次结构。

    好例子:

    com:
      company:
        feature: 
          config: value
    com.company.feature: default
    

    不好的例子

    com:
      company:
        feature:
          config: value
    com:
      company:
        feature: default
    

    如果您尝试执行之前的代码,那么根据 YAML,您将 com:company:feature 覆盖为 default 而不是 config: value

    【讨论】:

      猜你喜欢
      • 2019-10-15
      • 2015-05-31
      • 1970-01-01
      • 2016-01-17
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 2020-05-31
      • 2020-01-23
      相关资源
      最近更新 更多