简体   繁体   中英

configuration.yml has an error: * Unrecognized field at: driverClass - DROPWIZARD

I'm getting the following error when launching a Dropwizard application that uses a database connection to MySQL:

configuration.yml has an error:
* Unrecognized field at: driverClass
Did you mean?:
  - database
  - server
  - metrics
  - logging

Configuration.yml:

server:
  applicationConnectors:
    - type: http 
    port: 9010
  adminConnectors:
    - type: http
    port: 9011
  database:
    driverClass: com.mysql.jdbc.Driver
    user: ppub_web
    password: password
    url: jdbc:mysql://url:to connect port

Configuration class:

public class ConfigurationClass extends Configuration{

@Valid
@NotNull    
@JsonProperty("database")
private DataSourceFactory datasourceFactory = new DataSourceFactory();

public DataSourceFactory getDataSourceFactory() {
        return datasourceFactory;
    }
}
  • Make sure that you class DataSourceFactory contains a field called driverClass
  • Make sure you Configuration.yml is formatted properly according to the yaml specification . According to the error message, you have the problem exactly because of that.
  • Make sure that fields in DataSourceFactory are accessible to Jackson (getters/setters or public fields or right Jackson annotations for allowing setting private fields)

PS You don't have to initialize datasourceFactory via new DataSourceFactory();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM