环境:
idea
win10
问题描述:
使用wiremock读取resources下的mock.json文件,浏览器报错
No response could be served as there are no stub mappings in this WireMock
代码如下
public void proxyMockTest(){
try {
stubFor(get(urlMatching(".*")).atPriority(10)
.willReturn(aResponse().proxiedFrom("https://www.baidu.com/")));
stubFor(get(urlEqualTo("categories_and_latest")).atPriority(1)
//通过json文件修改指定网页信息
.willReturn(aResponse().withBody(Files.readAllBytes(Paths
.get(WireMockTest.class.getResource("/mock.json")
.toURI())))));
Thread.sleep(50000);
} catch (Exception e) {
e.printStackTrace();
}
报错解决方案:
在resources文件下增加mocks文件夹,那么在上面的项目中,路径变成resources/mocks/mock.json,即可解决