我正在尝试部署一个 Spring Boot 应用程序,但我无法更改其代码。我更喜欢使用 YML 配置它,但是我遇到了此 YAML 限制:
Elements have a value or children, never both.
应用程序的配置方案包括以下多个实例:
com.company.feature=default
com.company.feature.config=value
有没有办法将它们配置为 YAML,因为以下内容无效:
com:
company:
feature: default
config: value
最佳答案
您不能将所有内容都放在一个层次结构中。其键具有子级和值的任何属性都必须与不带层次结构的值一起列出。
好例子:
com:
company:
feature:
config: value
com.company.feature: default
坏例子
com:
company:
feature:
config: value
com:
company:
feature: default
如果您尝试执行以前的代码,则根据 YAML,您会使用 default
而不是 config: value
覆盖 com:company:feature
关于Spring Boot YAML 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35587616/