问题
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]
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 This question is similar to this one: UnrecognizedPropertyException While Reading A YAML File. However, that solution didn't work for me.
回答1:
Edit: check the example application here and here.
@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.
I've checked on old version of Dropwizard
and number 2 is your most immediate problem.
来源:https://stackoverflow.com/questions/40660710/unrecognized-field-in-dropwizard-yaml-file