识别Spring WebClient使用的UriBuilder实现

问题描述

我使用以下语法使用get client进行get调用。在下面的示例中,正在使用哪个URIBuilder实现,以及如何自动推断?

webclient.get().uri(uriBuilder -> uriBuilder.path("/api/person/{personId}")
    .queryParam("param1",aDouble)
    .queryParam("param2","A string value with spaces")
    .queryParam("param3",aListOfValues)
    .queryParam("param4",null)
    .build(anInteger))

这是我正在使用的网络客户端-WebClient

解决方法

您可以通过在构建WebClient时提供UriBuilderFactory来决定使用哪种实现WebClient.Builder

uriBuilderFactory(UriBuilderFactory)有一个DefaultUriBuilderFactory方法,您可以在其中提供实现。

如果您不提供一个,则它当前使用UriComponentsBuilder来产生{{3}}个实例。


您始终可以检测代码以打印uriBuilder.getClass()进行确认。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...