在使用 dropwizard 时,
我的 dropwizard 服务读取 config.yml 文件。
public void run() throws Exception {
this.run(new String[] { "server", "src/main/resources/config.yml" });
}
配置.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) 杰克逊如何忽略属性 http://wiki.fasterxml.com/JacksonHowToIgnoreUnknown
他们都没有帮忙。谁能指出我在这里可能缺少什么?