Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring rest文档无法使用WebTestClient记录pathParameters_Java_Spring Webflux_Spring Restdocs - Fatal编程技术网

Java Spring rest文档无法使用WebTestClient记录pathParameters

Java Spring rest文档无法使用WebTestClient记录pathParameters,java,spring-webflux,spring-restdocs,Java,Spring Webflux,Spring Restdocs,升级到Spring-test-5.3.0-SNAPSHOT后,Spring rest文档无法记录路径参数,并抱怨无法找到urlTemplate webTestClient.mutateWith(csrf()).get() .uri("/products/{productId}", productId) .accept(MediaType.APPLICATION_JSON) .exchange() .expectS

升级到Spring-test-5.3.0-SNAPSHOT后,Spring rest文档无法记录路径参数,并抱怨无法找到
urlTemplate

webTestClient.mutateWith(csrf()).get()
        .uri("/products/{productId}", productId)
        .accept(MediaType.APPLICATION_JSON)
        .exchange()
        .expectStatus().isOk()
        .expectHeader().contentType(MediaType.APPLICATION_JSON)
        .expectBody()
        .consumeWith(document("find-product-by-id",
                pathParameters(
                        parameterWithName("productId").description("...")
                ),
                responseFields(getProductResponseFields())));
错误日志:

urlTemplate not found. If you are using MockMvc did you use RestDocumentationRequestBuilders to build the request?
java.lang.IllegalArgumentException: urlTemplate not found. If you are using MockMvc did you use RestDocumentationRequestBuilders to build the request?
    at org.springframework.util.Assert.notNull(Assert.java:201)
    at org.springframework.restdocs.request.PathParametersSnippet.extractUrlTemplate(PathParametersSnippet.java:126)
    at org.springframework.restdocs.request.PathParametersSnippet.extractActualParameters(PathParametersSnippet.java:113)
    at org.springframework.restdocs.request.AbstractParametersSnippet.verifyParameterDescriptors(AbstractParametersSnippet.java:89)
    at org.springframework.restdocs.request.AbstractParametersSnippet.createModel(AbstractParametersSnippet.java:74)
    at org.springframework.restdocs.request.PathParametersSnippet.createModel(PathParametersSnippet.java:98)
    at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:78)
    at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:191)
    at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.lambda$document$0(WebTestClientRestDocumentation.java:77)
    at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.lambda$consumeWith$3(DefaultWebTestClient.java:665)
    at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:223)
    at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.consumeWith(DefaultWebTestClient.java:665)

在构造uri时,DefaultWebTestClient似乎正在将uriTemplate设置为null,但找不到覆盖它的方法。

不幸的是,最新的Spring Framework 5.3快照中出现了一个回归,我认为您无法解决它。我提出了一个建议。同时,您可以使用Spring Framework 5.3.0.RC1,因为它是在问题出现之前发布的。

不幸的是,最新的Spring Framework 5.3快照中出现了倒退,我认为您无法解决它。我提出了一个建议。同时,您可以使用问题出现之前发布的Spring Framework 5.3.0.RC1。

您应该创建错误报告。您确定
DefaultWebTestClient
正在将
uriTemplate
设置为
null
?查看它只会在使用
URI
函数调用时执行此操作,而上面的代码并没有执行此操作。它正在调用
uri(stringuritemplate,Object…uriVariables)
来设置模板。所有的uri方法最终都会调用
RequestBodySpec uri(uriuriuri uri)
方法,该方法将uriTemplate设置为null,所以我使用的方法并不重要@你说得对。抱歉,我没有注意到您正在使用5.3快照。您应该创建一个错误报告。您确定
DefaultWebTestClient
正在将
uriTemplate
设置为
null
?查看它只会在使用
URI
函数调用时执行此操作,而上面的代码并没有执行此操作。它正在调用
uri(stringuritemplate,Object…uriVariables)
来设置模板。所有的uri方法最终都会调用
RequestBodySpec uri(uriuriuri uri)
方法,该方法将uriTemplate设置为null,所以我使用的方法并不重要@你说得对。抱歉,我没有注意到您正在使用5.3快照。