Created
April 30, 2025 17:47
-
-
Save drub0y/039ecf7281fc78d8539b8e201ae1f4d3 to your computer and use it in GitHub Desktop.
Canonical Spring RestClient + JDK HttpClient configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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