【问题标题】:How do I solve this error in dropwizard config file?如何解决 dropwizard 配置文件中的此错误?
【发布时间】:2020-04-14 09:01:31
【问题描述】:

当我在使用时运行我的 jar 时出现以下错误:

java -jar <jarPath>.jar server config.yml

错误:

  * Configuration at config.yml must not be empty

        at io.dropwizard.configuration.ConfigurationParsingException$Builder.build(ConfigurationParsingException.java:279)
        at io.dropwizard.configuration.BaseConfigurationFactory.build(BaseConfigurationFactory.java:85)
        at io.dropwizard.cli.ConfiguredCommand.parseConfiguration(ConfiguredCommand.java:126)
        at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:74)
        at io.dropwizard.cli.Cli.run(Cli.java:79)
        at io.dropwizard.Application.run(Application.java:94)
        at com.flipkart.cx.taggingconsole.webapp.application.DataConsoleApp.main(DataConsoleApp.java:62)

这里是我的配置文件,我对这一切都很陌生,并尝试使用 config.yml 而不是 hibernate.cfg.xml 将我的 dropwizard 应用程序连接到休眠。

请看一下 config.yml 文件

server:
  applicationConnectors:
    -   type: http
        port: 8800
  adminConnectors:
    -   type: http
        port: 9800
# Database settings.
database:

  # the name of your JDBC driver
  driverClass: com.mysql.jdbc.Driver

  # the username
  user: root

  # the password
  password: root1234

  # the JDBC URL
  url: jdbc:h2:./target/example
  properties:
    hibernate.dialect: org.hibernate.dialect.MySQLDialect
    hibernate.connection.url: jdbc:mysql://localhost/test
    hibernate.connection.driver_class: com.mysql.jdbc.Driver
    hibernate.show_sql: false
    hibernate.generate_statistics: false
    hibernate.hbm2ddl.auto: update # validates schema when service is started
    hibernate.current_session_context_class: thread

【问题讨论】:

  • 您的 yaml 文件中似乎有一些错误,因此无法解析。尝试删除 database 部分并检查它是否更进一步(它会因其他错误而下降),但通过添加/删除 yaml 的其他部分,您会发现问题出在哪里
  • 仍然出现同样的错误?还有什么办法解决吗?
  • 也许你真的有一个空文件config.yml?尝试将其复制到其他文件(config2.yml)并在运行命令中使用它。也许您指向错误的位置?
  • 你介意分享你的配置的sn-ps吗?
  • 即使使用最小的 yaml 文件(仅 http 应用程序连接器,端口 8080),我也会遇到同样的错误。 @AdityaVerma,如果您成功解决了您的问题,请发布答案

标签: java hibernate yaml dropwizard


【解决方案1】:

在我的情况下,我有由 fatjar 插件生成的 dropwizard 的应用程序 jar,因此它无法看到 jar 之外的文件。当我将我的config.yml 放到项目中的资源目录并再次编译应用程序时,它可以找到该文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多