Spring Boot YAML 配置

标签 spring spring-boot yaml

我正在尝试部署一个 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/

相关文章:

bash - 如何解决 Yaml 语法错误 'did not find expected key' - Azure Devops

docker - 将 args 传递给容器时 Kubernetes pod/部署?

enums - 使用 SnakeYAML 按值解析枚举

java - 如何正确计时用 Java Spring MVC 编写的配置文件 API?

Spring OAuth2多服务器注释配置(资源和授权)

java - 在 Hibernate/JPA 中,我应该在哪里以及在哪个用例中使用 SessionFactory 和 Session

java - Spring Boot 中的任务执行器

java - JPA ManyToMany - 始终在表中创建新值,即使该值存在

java - 通过 Spring by Environment 注入(inject)属性值

java - 框架(如Spring)如何在没有web.xml的情况下配置Servlet容器?