javaspring-mvcspring-reactive

Identifying UriBuilder implementation used by Spring 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


Solution

  • 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.


    You could always instrument your code to print uriBuilder.getClass() for confirmation.