首页 > 解决方案 > Wiremock - 自动配置不加载存根

问题描述

我的wiremock 似乎不适用于自动配置。我在类路径中名为 stubs 的文件夹中有 json 文件,我在端口 8080 上运行了独立 jar。

@AutoConfigureWireMock(stubs="classpath:/stubs", port = 0)
public class TestResource {

    @Autowired
    private Service service;

    @Test
    public void contextLoads() throws Exception {
        assertThat(this.service.go()).isEqualTo("Hello World!");
    }

}

json 文件示例

{
  "request" : {
    "url" : "/api/users",
    "method" : "GET",
    "bodyPatterns" : [ {
      "contains" : "some soap body"
    }]
  },
  "response" : {
    "status" : 200,
    "body" : "Hello World",
    "headers" : {
      "X-Application-Context" : "application:-1",
      "Content-Type" : "text/plain"
    }
  }
}

当我使用 GET -> localhost:8080/api/users/ 启动请求时,它与 json 文件不匹配。

提前致谢

标签: javaspringspring-bootstubwiremock

解决方案



推荐阅读