Wiremock报错:无法找到jwt助手{{{jwt maxAge='12 days'}}}
WireMock中JWT模板助手找不到的问题解决
问题重现
按官方文档配置JWT助手生成响应,配置文件thing.json内容如下:
{ "request": { "method": "GET", "url": "/some/thing" }, "response": { "status": 200, "body": "{{{jwt maxAge='12 days'}}}", "headers": { "Content-Type": "text/plain" } } }
运行后返回500错误,核心报错:
could not find helper'jwt' {{{jwt maxAge='12 days'}}}
解决步骤
- 启用响应模板功能:JWT助手属于WireMock的响应模板扩展,默认未开启。启动WireMock时必须添加参数:
若通过Java代码启动,需在配置中启用:wiremock --enable-response-templatingWireMockServer server = new WireMockServer(options().enableResponseTemplating()); - 检查WireMock版本:JWT助手在WireMock 2.35.0及以上版本才被引入,使用旧版本需升级至符合要求的版本。
- 验证语法正确性:
{{{jwt maxAge='12 days'}}}的写法合规,三重花括号用于避免HTML转义,参数格式也符合官方要求,无需调整。
内容的提问来源于stack exchange,提问作者Belkasmi
相关产品推荐
相关产品推荐

