识别 Spring WebClient 使用的 UriBuilder 实现

huangapple go评论107阅读模式
英文:

Identifying UriBuilder implementation used by Spring WebClient

问题

我使用以下语法使用get客户端进行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

英文:

I use the below syntax to make a get call using get client. In the below example , which implementation of URIBuilder is being used and how is automatically inferenced?

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))

This is the webclient that I am using - WebClient

答案1

得分: 1

你可以在构建WebClient时通过提供UriBuilderFactory来决定使用哪种实现方式。

WebClient.Builder有一个uriBuilderFactory(UriBuilderFactory)方法,您可以在其中提供您的实现方式。

如果您没有提供实现方式,它目前会使用DefaultUriBuilderFactory,该工厂会生成UriComponentsBuilder实例。


<sub>您始终可以对您的代码进行调整,以打印出uriBuilder.getClass()以进行确认。</sub>

英文:

You can decide which implementation is used WebClient by providing a UriBuilderFactory while building it.

The WebClient.Builder has a uriBuilderFactory(UriBuilderFactory) method where you can provide your implementation.

If you don't provide one, it currently uses DefaultUriBuilderFactory which produces UriComponentsBuilder instances.


<sub>You could always instrument your code to print uriBuilder.getClass() for confirmation.</sub>

huangapple
  • 本文由 发表于 2020年8月28日 05:55:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63624634.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定