Unrecognized Field in Dropwizard YAML File

不打扰是莪最后的温柔 提交于 2020-01-03 17:35:31

问题


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.

  1. @JsonProperty() - there are extra brackets here.
  2. private static DataSourceFactory database; - remove static from here. Reference the docs for an example of how it should look.
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!