将模拟推送到远程Wiremock服务器失败,并出现“ JSON解析”错误

问题描述 投票:0回答:1

我正在尝试将映射从Spring应用程序发布到远程服务器。调试时发现,我的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"
  } ]
}

我从以下问题(到最后评论)获得了发布到远程独立服务器的详细信息。

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

我用于发布到远程服务器的代码如下:

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"
      }
    }
  ]
}
java spring wiremock wiremock-standalone
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.