首页 > 解决方案 > Dropwizard - 部署时,由于 yml 文件格式错误,应用程序无法运行

问题描述

我们正在尝试使用 Dropwizard 指标将自动化指标添加到我们的 Java 应用程序中。到目前为止,config.yml 文件如下所示:

metrics:
  reporters:
  - type: log
    logger: metrics
    frequency: 5 minute
    includes: "io.dropwizard.jetty.MutableServletContextHandler.active-requests","io.dropwizard.jetty.MutableServletContextHandler.active-dispatches","io.dropwizard.jetty.MutableServletContextHandler.active-suspended"

运行此项目时,我们收到一条错误消息,指出 yaml 文件格式错误:

io.dropwizard.configuration.ConfigurationParsingException: test/config.yml has an error:
  * Malformed YAML at line: 24, column: 82; while parsing a block mapping
 in 'reader', line 20, column 5:
      - type: log
        ^
expected <block end>, but found FlowEntry
 in 'reader', line 23, column 81:
     ... tContextHandler.active-requests","io.dropwizard.jetty.MutableSer ...
                                         ^

这里写 yaml 的方式到底有什么问题?我的理解是,缩进、空格和引号内没有逗号是正确的,我们无法找到任何其他问题。

标签: javaformatdropwizardmetrics

解决方案


只需将第 6 行更改为

includes: [io.dropwizard.jetty.MutableServletContextHandler.active-requests,io.dropwizard.jetty.MutableServletContextHandler.active-dispatches,io.dropwizard.jetty.MutableServletContextHandler.active-suspended]


推荐阅读