启动使用数据库连接到MySQL的Dropwizard应用程序时出现以下错误:

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


配置类:

public class ConfigurationClass extends Configuration{

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

public DataSourceFactory getDataSourceFactory() {
        return datasourceFactory;
    }
}

最佳答案

确保您的课程DataSourceFactory包含一个名为driverClass的字段
确保Configuration.yml的格式符合yaml规范。根据错误消息,您正是因为此而有问题。
确保DataSourceFactory中的字段可供Jackson访问(获取程序/设置程序或公共字段,或用于设置私有字段的正确Jackson注释)


附言您不必通过datasourceFactory初始化new DataSourceFactory();

09-26 03:04