Skip to content

Instantly share code, notes, and snippets.

@drub0y
Created April 30, 2025 17:47
Show Gist options
  • Save drub0y/039ecf7281fc78d8539b8e201ae1f4d3 to your computer and use it in GitHub Desktop.
Save drub0y/039ecf7281fc78d8539b8e201ae1f4d3 to your computer and use it in GitHub Desktop.
Canonical Spring RestClient + JDK HttpClient configuration
@Configuration
public class RestClientConfig {
@Bean
public RestClient myRestClient(final RestClient.Builder restClientBuilder) {
final var httpClient = HttpClient
.newBuilder()
.version(HttpClient.Version.HTTP_2)
.executor(Executors.newVirtualThreadPerTaskExecutor())
.build();
final var jdkClientHttpRequestFactory = new JdkClientHttpRequestFactory(httpClient);
// TODO: configure other settings here such as read timeout
return restClientBuilder.requestFactory(jdkClientHttpRequestFactory).build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment