[英]Unrecognized Field in Dropwizard YAML File
I'm getting the following error when launching a Dropwizard application that uses a database connection to MySQL: 启动使用数据库连接到MySQL的Dropwizard应用程序时出现以下错误:
app.yaml has an error:
* Unrecognized field at: database
Did you mean?:
- metrics
- instanceId
- logging
- server
- statsConfig
[12 more]
At the end of my Dropwizard configuration file, I have the following: 在我的Dropwizard配置文件的末尾,我有以下内容:
database:
driverClass: com.mysql.jdbc.Driver
user: ${MYSQL_USERNAME}
password: ${MYSQL_PASSWORD}
url: ${MYSQL_URL}
And in my configuration class, I have the following: 在配置类中,我具有以下内容:
@Valid()
@NotNull()
@JsonProperty()
private static DataSourceFactory database;
public static DataSourceFactory getDatabase() {
return database;
}
public static void setDatabase(final DataSourceFactory database) {
AppConfig.database = database;
}
Several other complex configuration objects are loading correctly (it's a pretty big config file), but this one is not. 其他几个复杂的配置对象正在正确加载(这是一个很大的配置文件),但事实并非如此。 Any ideas why I'm getting this error?
有任何想法为什么我会收到此错误吗?
EDIT This question is similar to this one: UnrecognizedPropertyException While Reading A YAML File . 编辑此问题类似于以下问题: 读取YAML文件时UnrecognizedPropertyException 。 However, that solution didn't work for me.
但是,该解决方案对我不起作用。
Edit: check the example application here and here . 编辑:在此处和此处检查示例应用程序。
@JsonProperty()
- there are extra brackets here. @JsonProperty()
-这里有多余的括号。 private static DataSourceFactory database;
- remove static
from here. static
。 Reference the docs for an example of how it should look. = new DataSourceFactory();
= new DataSourceFactory();
as per docs and this question . I've checked on old version of Dropwizard
and number 2 is your most immediate problem. 我检查了
Dropwizard
旧版本,而2是您最直接的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.