Dropwizard YAML文件中无法识别的字段 [英] Unrecognized Field in Dropwizard YAML File
问题描述
启动使用与MySQL的数据库连接的Dropwizard应用程序时出现以下错误:
I'm getting the following error when launching a Dropwizard application that uses a database connection to MySQL:
app.yaml has an error:
* Unrecognized field at: database
Did you mean?:
- metrics
- instanceId
- logging
- server
- statsConfig
[12 more]
在Dropwizard配置文件的末尾,我具有以下内容:
At the end of my Dropwizard configuration file, I have the following:
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 这个问题与此类似:在读取YAML文件时出现UnrecognizedPropertyException 。但是,该解决方案对我不起作用。
EDIT This question is similar to this one: UnrecognizedPropertyException While Reading A YAML File. However, that solution didn't work for me.
推荐答案
编辑:检查示例应用程序< a href = https://github.com/dropwizard/dropwizard/blob/master/dropwizard-example/src/main/java/com/example/helloworld/HelloWorldConfiguration.java#L53-L61 rel = nofollow noreferrer >此处和此处。
check the example application here and here.
-
@JsonProperty()
-这里有多余的括号。 -
私有静态DataSourceFactory数据库;
-删除static
从这里开始。有关外观的示例,请参考文档。 - 还要根据文档和
= new DataSourceFactory(); Questions / 30079790 /在数据库中无法识别的字段-您平均计量服务器日志记录>此问题。
@JsonProperty()
- there are extra brackets here.private static DataSourceFactory database;
- removestatic
from here. Reference the docs for an example of how it should look.- Also add the
= new DataSourceFactory();
as per docs and this question.
我已经检查过旧版本的 Dropwizard
,而数字2是您最直接的问题。
I've checked on old version of Dropwizard
and number 2 is your most immediate problem.
这篇关于Dropwizard YAML文件中无法识别的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!