Java 无法设置wiremock服务器端口

Java 无法设置wiremock服务器端口,java,stub,wiremock,Java,Stub,Wiremock,我正在尝试配置wiremock端口。它总是给出下面的例外。我使用的是最新版本2.8.0 Exception in thread "main" org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect at org.apache.http.im

我正在尝试配置wiremock端口。它总是给出下面的例外。我使用的是最新版本2.8.0

Exception in thread "main" org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at com.github.tomakehurst.wiremock.client.HttpAdminClient.safelyExecuteRequest(HttpAdminClient.java:380)
at com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:368)
at com.github.tomakehurst.wiremock.client.HttpAdminClient.addStubMapping(HttpAdminClient.java:110)
at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:273)
at com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:268)
at com.github.tomakehurst.wiremock.client.WireMock.givenThat(WireMock.java:99)
at com.github.tomakehurst.wiremock.client.WireMock.stubFor(WireMock.java:103)
at Testme.main(Testme.java:18)
这是我的密码

 public static void main(String args[])
{
    System.out.println("Starting server");
    WireMockServer wireMockServer = new WireMockServer(8090);
    //Tried this one as well
    //options.port(8090)
    //WireMock.configureFor(8090);
    wireMockServer.start();

    stubFor(get(urlEqualTo("/my/resource"))
            .withHeader("Accept", equalTo("text/xml"))
            .willReturn(aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "text/xml")
                    .withBody("<response>Some content</response>")));
}
publicstaticvoidmain(字符串参数[])
{
System.out.println(“启动服务器”);
WireMockServer WireMockServer=新的WireMockServer(8090);
//我也试过这个
//选项.端口(8090)
//WireMock.configureFor(8090);
wireMockServer.start();
stubFor(get(urlEqualTo(“/my/resource”))
.withHeader(“接受”,equalTo(“文本/xml”))
.willReturn(aResponse()
.withStatus(200)
.withHeader(“内容类型”、“文本/xml”)
.withBody(“某些内容”);
}
我使用:

WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options().port(PORT));

您已经这样尝试过了吗?

当前最新版本
2.11.0
。以下语法适用

WireMockServer WireMockServer=new WireMockServer(new WireMockServer().port(8088)
您正在调用的静态
stubFor()
方法在默认的WireMock实例上创建存根。创建存根时,您需要使用
WireMockServer
的实例

wireMockServer.stubFor(...);

我使用的是最新的2.8.0版本,不管我得到什么:连接到本地主机:8080[localhost/127.0.0.1]失败:连接被拒绝(连接被拒绝)这也得到了连接到本地主机:8080[localhost/127.0.0.1]失败:连接被拒绝(连接被拒绝)