6

Spring Boot 1.5.1.RELEASE および Wiremock 2.5.1 でテスト インフラストラクチャを構成しようとすると問題が発生します。それは投げています:

java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
    at com.github.tomakehurst.wiremock.core.WireMockApp.buildStubRequestHandler(WireMockApp.java:124)
    at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:71)
    at com.github.tomakehurst.wiremock.junit.WireMockRule.<init>(WireMockRule.java:42)
    at com.github.tomakehurst.wiremock.junit.WireMockRule.<init>(WireMockRule.java:38)
    at br.com.mobicare.minhaoi.WiremockTest.<clinit>(WiremockTest.java:21)
    at sun.misc.Unsafe.ensureClassInitialized(Native Method)
    at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
    at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
    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.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:253)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 28 more

別のプロジェクトで Wiremock 2.4.1 と Spring Boot 1.3.0.M5 を使用しましたが、この問題は一度もありませんでした。

私のテストクラス:

@RunWith(SpringRunner.class)
@SpringBootTest
@WebAppConfiguration
public class WiremockTest {

    @ClassRule
    public static WireMockRule wireMockRule = new WireMockRule(options().port(8888).notifier(new ConsoleNotifier(true)));

    @Test
    public void testStub() {
        wireMockRule.stubFor(get(urlEqualTo("/test"))
                .willReturn(aResponse()
                        .withHeader("Content-type", "application/json").withStatus(200)));
    }

}

Spring Boot のバージョン 1.3.0.M5 以降、一部のテスト アノテーションが変更されていることに気付きました。これが問題である可能性があると思います。誰かが同じ問題を抱えていましたか?

ありがとう、

4

3 に答える 3