* Unrecognized field at: database Did you mean?: - metrics - server - logging - DROPWIZARD

☆樱花仙子☆ 提交于 2019-12-07 03:13:21

问题


I cannot start my dropwizard application after add database details in my application configuration file (server.yml).

server.yml (app config file)

server:
  applicationConnectors:
  - type: http 
    port: 8080
  adminConnectors:
  - type: http
    port: 9001

database:
  # the name of your JDBC driver
  driverClass: org.postgresql.Driver

  # the username
  user: dbuser

  # the password
  password: pw123

  # the JDBC URL
  url: jdbc:postgresql://localhost/database

  # any properties specific to your JDBC driver:
  properties:
    charSet: UTF-8

  # the maximum amount of time to wait on an empty pool before throwing an exception
  maxWaitForConnection: 1s

  # the SQL query to run when validating a connection's liveness
  validationQuery: "/* MyService Health Check */ SELECT 1"

  # the timeout before a connection validation queries fail
  validationQueryTimeout: 3s

  # the minimum number of connections to keep open
  minSize: 8

  # the maximum number of connections to keep open
  maxSize: 32

  # whether or not idle connections should be validated
  checkConnectionWhileIdle: false

  # the amount of time to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing
  evictionInterval: 10s

  # the minimum amount of time an connection must sit idle in the pool before it is eligible for eviction
  minIdleTime: 1 minute

As result of run dropwizard application I can see:

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

回答1:


In addition to code given by dropwizard example you need to add a setter for database property.

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

public DataSourceFactory getDataSourceFactory() {
    return database;
}

public void setDatabase(DataSourceFactory database) {
    this.database = database;
}



回答2:


In your application configuration java file, you have to add the matching property for "database". If the properties you're specifying are the standard ones (which they look to be, good!) then you can keep with the DataSourceFactory type:

public class ExampleConfiguration extends Configuration {
    @Valid
    @NotNull
    @JsonProperty
    private DataSourceFactory database = new DataSourceFactory();

    public DataSourceFactory getDataSourceFactory() {
        return database;
    }

    public void setDatabase(DataSourceFactory database) {
        this.database = database;
    }
}

Example here: http://www.dropwizard.io/0.9.0/docs/manual/jdbi.html



来源:https://stackoverflow.com/questions/30079790/unrecognized-field-at-database-did-you-mean-metrics-server-logging

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