YAML 配置文件中的重复键

6 yaml snakeyaml spring-boot

在 YAML 中有以下内容-

key1
  key2: "value"

key1
  key2
    key3: "value2"
Run Code Online (Sandbox Code Playgroud)

获取异常重复键 key1。引起:org.yaml.snakeyaml.parser.ParserException:同时解析 MappingNode

尝试各种组合但无法正确解析。

有人可以在这里提供帮助或指导。

谢谢

fly*_*lyx 8

您的 YAML 在语法上无效,但我假设它实际上是这样的:

key1:
  key2: "value"

key1:
  key2:
    key3: "value2"
Run Code Online (Sandbox Code Playgroud)

您的错误是key1在根节点中用作映射键两次。根据YAML 规范,这是非法的:

映射节点的内容是一组无序的键:值节点对,限制是每个键都是唯一的。

解决方案是使同一映射的所有键都是唯一的:

key11:
  key2: "value"

key12:
  key2:
    key3: "value2"
Run Code Online (Sandbox Code Playgroud)


小智 6

我也面临同样的问题。然后它击中了我!答案很简单。从

mapping:
  refresh:
    schedule:
      frequency:
        milli: 86400000
mapping:
  refresh:
    schedule:
      initial:
        delay:
          ms: 30000
Run Code Online (Sandbox Code Playgroud)

mapping:
  refresh:
    schedule:
      frequency:
        milli: 86400000
      initial:
        delay:
          ms: 30000
Run Code Online (Sandbox Code Playgroud)