4

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 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.