WireMock 的時候報錯:No response could be served as there are no stub mappings in this WireMock

楚塵的海底世界發表於2020-12-14

環境:
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,即可解決

相關文章