将模拟推送到远程 wiremock 服务器失败并显示"JSON Parsing"错误



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

Error creating bean with name 'wiremockConfig' defined in file [C:UsersAddyschool-impl-apitargetclassescomtestschoolprojectwiremockWiremockConfig.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"
}
}
]
}

在聊天中讨论后发现,支持将每个映射保存在一个单独的文件中。以下是负责此操作的源代码:RemoteMappingsLoader#load

最新更新