java – 读取yaml文件时出现UnrecognizedPropertyException
发布时间:2020-12-15 04:19:52 所属栏目:Java 来源:网络整理
导读:在使用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
在使用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 他们都没有帮助.谁能指出我在这里可能会缺少什么? 解决方法
将以下行添加到配置类
@Valid @NotNull @JsonProperty private DataSourceFactory database = new DataSourceFactory(); public DataSourceFactory getDataSourceFactory() { return database; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |