gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 17:03:49 25 4
gpt4 key购买 nike

我正在尝试从 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"
}
}
]
}

最佳答案

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

关于java - 将模拟推送到远程wiremock服务器失败并出现 "JSON Parsing"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61476865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com