What is the meaning of UriComponentsBuilder?
Matthew Barrera
I get an example UriComponentsBuilder while learning spring boot. I don't know the meaning of UriComponentsBuilder and the function of UriComponentsBuilder.
2 Answers
Yes, this used for constructing URI. Particularly useful when you want to invoke webservices in your class. Eg:
String baseUri = "/sample-uri"
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uri);
builder.queryParam("id", "1");
String uri= builder.build().encode().toUriString();It is evident that you can pass additional params, to this. This provide a clean and efficient way of creating uris than writing those as plain text.
0It is a factory class for getting instances of UriComponents which are helpful for constructing URIs.
Please go through the tutorial below, examples are also given here.