【问题标题】:dropwizard test integration give an exception ConfigurationParsingExceptiondropwizard 测试集成给出异常 ConfigurationParsingException
【发布时间】:2015-12-29 10:41:30
【问题描述】:

我目前正在使用框架 dropwizard、embeddedmongo 进行集成测试。但是当我执行测试时,我总是这个异常。

com.example.pointypatient.integration.PointyPatientApplicationTest  Time elapsed: 3.054 sec  <<< ERROR!
java.lang.RuntimeException: io.dropwizard.configuration.ConfigurationParsingException: dropwizard-angular- example-master\target\test-classes\integration.yml has an error:Configuration at dropwizard-angular-example-master\target\test-classes\integration.yml must not be empty

我的 integration.yml 在这里:

dbConfig:
  host: localhost
  port: 12345
  dbName: test

server:
  applicationConnectors:
    - type: http
      port: 8080
    - type: https
      port: 8443
      keyStorePath: example.keystore
      keyStorePassword: example
      validateCerts: false
  adminConnectors:
    - type: http
      port: 8081
    - type: https
      port: 8444
      keyStorePath: example.keystore
      keyStorePassword: example
      validateCerts: false

# Logging settings.
logging:
  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
  level: INFO

  appenders:
    - type: console

感谢您的帮助

【问题讨论】:

    标签: java mongodb jetty yaml dropwizard


    【解决方案1】:

    来自ConfigurationFactory.java,仅当来自ObjectMapper 的方法readTree 返回null 时才会引发此异常。

    • 查看您传递给build 方法的ConfigurationSourceProvider 派生类,因为它没有正确处理IOException(我可以假设您使用的是模拟的);
    • 查看path 参数,您似乎应该传递 "dropwizard-angular-example-master\target\test-classes\integration.yml" 而不是 "dropwizard- angular-example-master\target\test-classes\integration.yml" *第一个路径在 dropwizard-angular- 之后有一个空格

    【讨论】:

      【解决方案2】:

      如果您的 dropwizard-config 文件(即integration.yml)位于test/resources 目录中,则无需使用ResourceHelpers.resourceFilePath("integration.yml") 将完整配置路径作为参数传递给DropwizardAppExtension,您应该只传递它的名称(例如“integration.yml”)

      private static DropwizardAppExtension<MyDropwizardConfiguration> RULE = new DropwizardAppExtension<>(
                  MyDropwizardApplication.class, "integration.yml");
      

      【讨论】:

        猜你喜欢
        • 2015-02-12
        • 2017-12-19
        • 1970-01-01
        • 2022-01-02
        • 2016-07-27
        • 1970-01-01
        • 1970-01-01
        • 2019-04-11
        • 1970-01-01
        相关资源
        最近更新 更多