Java 托马斯·赫斯特·威莫克。尝试连接到8080。拒绝连接

Java 托马斯·赫斯特·威莫克。尝试连接到8080。拒绝连接,java,junit5,wiremock,Java,Junit5,Wiremock,出现错误: org.apache.http.conn.HttpHostConnectException:连接到 localhost:8080[localhost/127.0.0.1]失败:连接被拒绝 (连接被拒绝) 你错过了什么 另外,我将WireMockServer与junit5和spring引导一起使用。使用junit4和WireMockRule都能很好地工作 @Test void resourceTo_Wired_ClientCall() { wireMockSe

出现错误:

org.apache.http.conn.HttpHostConnectException:连接到 localhost:8080[localhost/127.0.0.1]失败:连接被拒绝 (连接被拒绝)

你错过了什么

另外,我将
WireMockServer
junit5
和spring引导一起使用。使用
junit4
WireMockRule
都能很好地工作

@Test
    void resourceTo_Wired_ClientCall() {

        wireMockServer = new WireMockServer(options().port(10021));
        wireMockServer.start();

            final MappingBuilder stubBuilder = get(urlMatching("http://demo1096495.mockable.io/client1"));

            stubFor(stubBuilder
                    .willReturn(aResponse()
                            .withStatus(200)
                            .withHeader("Content-Type", "application/json")
                            .withBody("{\"something\":\"test-wired\"}")));
            ;
更新:

添加:
WireMock.configureFor(“localhost”,10021)

wireMockServer.start()之前

那么这个错误就消失了。它传递到下一行

附言。
得到了一些新东西。但这是另一个问题。

在实际测试中,您从哪里得到错误?您只发布了Wiremock设置。如果你的端口是10021,为什么测试试图连接到:8080?它发生在stubFor(..)上。问题的实际原因是:)(使用junit4和WireMockRule配置,它工作得很好)旁注:由于你使用的是
stubFor
作为静态方法,你可以配置默认使用
8080
端口的defualt wiremock实例。如果要为在测试中创建的实例创建存根,应在实例上使用
wireMockServer.stubFor
 testCompile "com.github.tomakehurst:wiremock-jre8:2.24.1"