【发布时间】:2014-04-30 18:55:55
【问题描述】:
在使用 dropwizard 时,
我的 dropwizard 服务读取 config.yml 文件。
public void run() throws Exception {
this.run(new String[] { "server", "src/main/resources/config.yml" });
}
Config.yml 文件:
database:
# the name of your JDBC driver
driverClass: com.mysql.jdbc.Driver
# the username
user: user2connect
# the password
password: password2connect
# the JDBC URL
url: jdbc:mysql://url.to.connect:port
但是,一旦文件被读取,我就会收到一个错误 -
Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "database" (class com.service.config.DropWizardConfiguration), not marked as ignorable (4 known properties: , "http", "httpConfiguration", "logging", "loggingConfiguration"])
at [Source: N/A; line: -1, column: -1] (through reference chain: com.service.config.DropWizardConfiguration["database"])
在浏览了几个主题之后,我意识到这可能是因为杰克逊无法忽略一些属性。
我尝试了几件事 -
1) 添加注解@JsonIgnoreProperty(但不确定我是否在预期位置添加)
2)Jackson how to ignore properties
他们都没有帮助。谁能指出我在这里可能缺少的东西?
【问题讨论】:
-
你能贴出你的应用配置类的代码吗?
标签: java web-services yaml dropwizard