Make RestTemplateBuilder more compatible with RestClient.Builder

When Spring Framework builds a `RestClient` from a `RestTemplate`, it
will use any `UriTemplateHandler` that has been set on the
`RestTemplate` if the provided `UriTemplateHandler` is also a
`UriBuilderFactory`. Prior to this commit, Spring Boot's
`RestTemplateBuilder#rootUri` set a `UriTemplateHandler` on the created
`RestTemplate`, but it was not a `UriBuilderFactory` so `RestClient`
would not consider it.

With this commit, `RestTemplateBuilder#rootUri` sets a
`UriTemplateHandler` that is also a `UriBuilderFactory` so that any
root URI that is set on the `RestTemplateBuilder` will be applied to a
`RestClient` also.

Fixes gh-39317
This commit is contained in:
Scott Frederick
2024-02-13 13:10:55 -06:00
parent a0cb2bdeaf
commit 720e9cef16
9 changed files with 271 additions and 15 deletions

View File

@@ -171,8 +171,8 @@ public class TestRestTemplate {
}
/**
* Returns the root URI applied by a {@link RootUriTemplateHandler} or {@code ""} if
* the root URI is not available.
* Returns the root URI applied by {@link RestTemplateBuilder#rootUri(String)} or
* {@code ""} if the root URI has not been applied.
* @return the root URI
*/
public String getRootUri() {