Java 8 Dropwizard测试-ResourceTestRule抛出NoClassDefFoundError:ch/qos/logback/core/filter/filter

Java 8 Dropwizard测试-ResourceTestRule抛出NoClassDefFoundError:ch/qos/logback/core/filter/filter,java-8,dropwizard,Java 8,Dropwizard,我正在使用dropwizard 1.2.4和log4j 1.2.17。我已按照以下说明进行操作 它在单元测试期间抛出如下异常 java.lang.NoClassDefFoundError: ch/qos/logback/core/filter/Filter at io.dropwizard.testing.junit.ResourceTestRule.<clinit>(ResourceTestRule.java:34) at com.vnera.restapila

我正在使用dropwizard 1.2.4和log4j 1.2.17。我已按照以下说明进行操作

它在单元测试期间抛出如下异常

java.lang.NoClassDefFoundError: ch/qos/logback/core/filter/Filter

    at io.dropwizard.testing.junit.ResourceTestRule.<clinit>(ResourceTestRule.java:34)
    at com.vnera.restapilayer.api.resources.ApiInfoControllerTest.<clinit>(ApiInfoControllerTest.java:25)
    at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
    at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:156)
    at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
    at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
    at java.lang.reflect.Field.get(Field.java:393)
    at org.junit.runners.model.FrameworkField.get(FrameworkField.java:73)
    at org.junit.runners.model.TestClass.getAnnotatedFieldValues(TestClass.java:230)
    at org.junit.runners.ParentRunner.classRules(ParentRunner.java:255)
    at org.junit.runners.ParentRunner.withClassRules(ParentRunner.java:244)
    at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:194)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:362)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.filter.Filter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 19 more
我的主要应用程序运行良好。主应用程序的
配置.yaml
如下所示

import io.dropwizard.testing.junit.ResourceTestRule;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import javax.ws.rs.core.Response;

import static org.mockito.Mockito.mock;

@Category(value = UnitTest.class)
public class ApiInfoControllerTest {
    private static ApiNonFunctionalHandler nonFunctionalHandler = mock(ApiNonFunctionalHandler.class);
    private static ApiFilter apiFilter = new ApiFilter(nonFunctionalHandler);
    private static final String authToken = "NetworkInsight xTyAGJmZ8nU8yJDP7LnA8Q==";

    @ClassRule
    public static final ResourceTestRule resources = ResourceTestRule.builder()
            .addResource(new ApiInfoController())
            .addProvider(apiFilter).build();

    @Test
    public void testApiVersion() throws Exception {
        Response response = resources.client()
                .target(ApiConstants.INFO_BASE_URL + "/version")
                .request()
                .header("Authorization", authToken)
                .buildGet().invoke();

        Assert.assertNotNull(response);
        Assert.assertEquals(response.toString(), Response.Status.OK.getStatusCode(), response.getStatus());
        final VersionResponse actualError = response.readEntity(VersionResponse.class);
        Assert.assertEquals(actualError.getApiVersion(), ApiConstants.API_VERSION);
    }
}
# Change default server ports
server:
  applicationConnectors:
  - type: http
    port: 8123
  adminConnectors:
  - type: http
    port: 8124
  requestLog:
    type: external
logging:
  type: external
有人能告诉我哪里出了问题,我该如何解决

编辑
mvn dependency:tree的输出被放置在这里,因为我达到了字符限制。

这是dropwizard 1.2.4中的一个错误,如下所述


链接项目的
pom.xml
明确排除了
logbackcore
。你也这样做吗?是的,我已经排除了。我认为这可能是异常的原因,因为它正在寻找
logback
类。我已经编辑了这个问题并添加了
mvn dependency:tree
的输出。如果不排除
logback core
,会发生什么情况?由于使用log4j时存在多个slf4j绑定,这会给我带来一些其他错误。我的目标是在dropwizard中使用log4j。