使用dropwizard時,讀取yaml文件時發生UnrecognizedPropertyException
我的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
他們沒有幫助。任何人都可以指出我可能會在這裏失蹤嗎?
你能後的代碼爲你的應用程序配置類? – condit