-
Notifications
You must be signed in to change notification settings - Fork 41.9k
Java system properties can not be applied to RestTemplate HttpClient connection in some cases #35815
Description
Spring boot 3.1.0 RestTemplateBuilder with apache HTTP client in classpath (org.apache.httpcomponents.client5:httpclient5) ignore java system HTTP proxy command line options like -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8888.
Spring boot before 3.1 respects such settings.
For simple RestTemplate restTemplate = restTemplateBuilder.build() spring boot 2.7 instantiate HttpComponentsClientHttpRequestFactory via default constructor, which create HTTP client as HttpClients.createSystem(), i.e. with system proxy support.
Spring boot 3.0 (if readTimeout duration is not set) also create HttpComponentsClientHttpRequestFactory via default constructor and HTTP client as HttpClients.createSystem().
But spring boot 3.1 create HTTP client as HttpClientBuilder.create().setConnectionManager(connectionManager).build(). Without useSystemProperties() as HttpClients.createSystem() makes.
Suggestion: add useSystemProperties() to createHttpClient method like this
return HttpClientBuilder.create()
.useSystemProperties()
.setConnectionManager(connectionManager)
.build();
For compatibility with spring boot 2.x, 3.0, and core spring HttpComponentsClientHttpRequestFactory.


