加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – pathParameters文档异常(urlTemplate未找到)

发布时间:2020-12-14 05:20:19 所属栏目:Java 来源:网络整理
导读:当使用pathParameters来记录URI路径参数时,如下所示 @Testpublic void documentGetRouteById() throws Exception { this.mockMvc.perform(get("/route/{id}","FooBar")).andExpect(status().isOk()) .andDo(document("api-getRouteById",pathParameters(para
当使用pathParameters来记录URI路径参数时,如下所示
@Test
public void documentGetRouteById() throws Exception {
    this.mockMvc.perform(get("/route/{id}","FooBar")).andExpect(status().isOk())
            .andDo(document("api-getRouteById",pathParameters(parameterWithName("id").description("die Routen ID"))));
}

我得到以下的兴趣

java.lang.IllegalArgumentException: urlTemplate not found. Did you use RestDocumentationRequestBuilders to build the request?
    at org.springframework.util.Assert.notNull(Assert.java:112)
    at org.springframework.restdocs.request.PathParametersSnippet.extractUrlTemplate(PathParametersSnippet.java:95)
    at org.springframework.restdocs.request.PathParametersSnippet.extractActualParameters(PathParametersSnippet.java:82)
    at org.springframework.restdocs.request.AbstractParametersSnippet.verifyParameterDescriptors(AbstractParametersSnippet.java:77)
    at org.springframework.restdocs.request.AbstractParametersSnippet.createModel(AbstractParametersSnippet.java:65)
    at org.springframework.restdocs.request.PathParametersSnippet.createModel(PathParametersSnippet.java:67)
    at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:64)
    at org.springframework.restdocs.mockmvc.RestDocumentationResultHandler.handle(RestDocumentationResultHandler.java:101)
    at org.springframework.test.web.servlet.MockMvc$1.andDo(MockMvc.java:158)

我很确定我做了测试设置,如解释here.

我可能做错了什么?

(Spring REST文档版本为1.0.0.BUILD-SNAPSHOT)

解决方法

异常信息正在试图指向正确的方向:

urlTemplate not found. Did you use RestDocumentationRequestBuilders to build the request?

您需要使用RestDocumentationRequestBuilders,以便Spring REST文档可以捕获URL并从中提取参数.这是mentioned in the documentation,它说:

To make the path parameters available for documentation,the request must be built using one of the methods on RestDocumentationRequestBuilders rather than MockMvcRequestBuilders.

将静态导入的MockMvcRequestBuilders.get替换为一个用于RestDocumentationRequestBuilders.get应该可以解决问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读