Skip to content

Creating a RestClient from a RestTemplateBuilder-created RestTemplate requires double configuration of the baseUrl/rootUri #39317

@wilkinsona

Description

@wilkinsona

You have do this:

RestClient rest = RestClient
	.builder(builder.setConnectTimeout(Duration.ofSeconds(30))
		.setReadTimeout(Duration.ofSeconds(30))
		.rootUri("https://example.com)
		.build())
	.defaultHeader("Authorization", "Bearer " + properties.token())
	.baseUrl("https://example.com")
	.build();

If you only configure rootUri on the RestTemplateBuilder, it's ignored by RestClient.Builder as the built RestTemplate has a UriTemplateHandler that isn't a UriBuilderFactory. If you only configure baseUrl on the RestClient.Builder it's ignored as the UriBuilderFactory from the RestTemplate is used instead. Configuring both prevents the UriBuilderFactory from the RestTemplate from being used which then allows the baseUrl on the RestClient.Builder to be honored.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions