java.lang.NoClassDefFoundError: io/dropwizard/jetty/RequestLogFactory when using dropwizard

java.lang.NoClassDefFoundError: io/dropwizard/jetty/RequestLogFactory when using dropwizard

当我从 Hibernate 更改为 JDBI 并尝试启动我的应用程序时,出现以下错误

java.lang.NoClassDefFoundError: io/dropwizard/jetty/RequestLogFactory

堆栈跟踪表明,此问题的原因是在我的配置 class 中的 class 定义中。但我不知道出了什么问题。有人遇到过这个问题吗?

MyConfiguration.java

import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
import io.dropwizard.db.DataSourceFactory;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;

public class MyConfiguration extends Configuration {

    @JsonProperty
    @NotNull
    private DataSourceFactory database;

    @JsonProperty
    @NotEmpty
    private String someString;


    public DataSourceFactory getDataSourceFactory() {
        return database;
    }

    public String getSomeString() {
        return someString;
    }
}

编辑 我正在使用 dropwizard 1.0.0,RequestLogFactory 既不在给定的包中,Intellij 也找不到 class.

我最好的猜测是您缺少 RequestLogFactory 的导入语句 class:

import com.fasterxml.jackson.annotation.JsonProperty;
import io.dropwizard.Configuration;
import io.dropwizard.db.DataSourceFactory;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;

您可能需要包括:

import io.dropwizard.jetty.RequestLogFactory;

或者干脆(如果你有更多 classes inside jetty):

import io.dropwizard.jetty.*;

您没有直接使用 RequestLogFactory,但似乎您正在导入的 classes 之一是并且该 jar 需要存在于您的 classpath 中才能用于这些 classes 你正在导入以在运行时正常工作。您应该找到您需要包含在包含 RequestLogFactory class 的 class 路径中的 jar。