将模拟推送到远程 wiremock 服务器失败,出现 "JSON Parsing" 错误

Pushing mocks to remote wiremock server fails with "JSON Parsing" Error

我正在尝试从 spring 应用程序 post 映射到远程服务器。我在调试时发现我的 JSON 被转换为 "StubMapping",这是代码失败并出现以下错误的地方。

Error creating bean with name 'wiremockConfig' defined in file [C:\Users\Addy\school-impl-api\target\classes\com\test\school\project\wiremock\WiremockConfig.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.test.order.implementation.product.wiremock.WiremockConfig$$EnhancerBySpringCGLIB$$b100848d]: Constructor threw exception; nested exception is com.github.tomakehurst.wiremock.common.JsonException: {
  "errors" : [ {
    "code" : 10,
    "source" : {
      "pointer" : "/mappings"
    },
    "title" : "Error parsing JSON",
    "detail" : "Unrecognized field \"mappings\" (class com.github.tomakehurst.wiremock.stubbing.StubMapping), not marked as ignorable"
  } ]
}

我从以下问题(最后一条评论)中获得了有关 posting 到远程独立服务器的详细信息。

https://github.com/tomakehurst/wiremock/issues/1138

我 posting 到远程服务器的代码是这样的:

WireMock wm = new WireMock("https", "wiremock-poc.apps.pcf.sample.int", 443);
wm.loadMappingsFrom("src/main/resources"); // Root dir contains mappings and __files

这会在我 运行 本地配置文件时加载。

请就如何解决此问题提供指导并进一步推进。

此致

更新:示例映射文件。

        {
  "mappings": [
    {
      "request": {
        "method": "GET",
        "urlPathPattern": "/school/admin/rest/users/([0-9]*)?([a-zA-Z0-9_\-\=\?\.]*)"
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json"
        },
        "bodyFileName": "./mockResponses/School-getUser.json"
      }
    }
  ]
}

chat 中的讨论后发现支持将每个映射保存在单独的文件中。 这是负责的source codeRemoteMappingsLoader#load