2222
2323import org .apache .commons .logging .Log ;
2424import org .apache .commons .logging .LogFactory ;
25+ import org .apache .hc .client5 .http .config .RequestConfig ;
26+ import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
27+ import org .apache .hc .client5 .http .impl .classic .HttpClients ;
28+ import org .apache .hc .client5 .http .impl .io .PoolingHttpClientConnectionManager ;
2529import org .apache .hc .core5 .util .Timeout ;
2630
2731import org .springframework .beans .factory .annotation .Value ;
2832import org .springframework .boot .SpringApplication ;
2933import org .springframework .boot .SpringBootConfiguration ;
3034import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
31- import org .springframework .boot .http .client .ClientHttpRequestFactoryBuilder ;
32- import org .springframework .boot .http .client .HttpComponentsClientHttpRequestFactoryBuilder ;
3335import org .springframework .cloud .client .DefaultServiceInstance ;
3436import org .springframework .cloud .loadbalancer .annotation .LoadBalancerClient ;
3537import org .springframework .cloud .loadbalancer .core .ServiceInstanceListSupplier ;
3638import org .springframework .cloud .loadbalancer .support .ServiceInstanceListSuppliers ;
3739import org .springframework .context .annotation .Bean ;
3840import org .springframework .http .HttpStatus ;
3941import org .springframework .http .ResponseEntity ;
42+ import org .springframework .http .client .HttpComponentsClientHttpRequestFactory ;
4043import org .springframework .web .bind .annotation .GetMapping ;
4144import org .springframework .web .bind .annotation .RequestParam ;
4245import org .springframework .web .bind .annotation .RestController ;
@@ -62,11 +65,19 @@ public static void main(String[] args) {
6265 }
6366
6467 @ Bean
65- public HttpComponentsClientHttpRequestFactoryBuilder httpComponentsClientHttpRequestFactoryBuilder () {
66- return ClientHttpRequestFactoryBuilder .httpComponents ()
67- .withConnectionManagerCustomizer (builder -> builder .setMaxConnTotal (2 ).setMaxConnPerRoute (2 ))
68- .withDefaultRequestConfigCustomizer (
69- c -> c .setConnectionRequestTimeout (Timeout .of (Duration .ofMillis (3000 ))));
68+ public HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory () {
69+ PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager ();
70+ connectionManager .setMaxTotal (2 );
71+ connectionManager .setDefaultMaxPerRoute (2 );
72+
73+ CloseableHttpClient httpClient = HttpClients .custom ()
74+ .setConnectionManager (connectionManager )
75+ .setDefaultRequestConfig (
76+ RequestConfig .custom ().setConnectionRequestTimeout (Timeout .of (Duration .ofMillis (3000 ))).build ())
77+ .build ();
78+
79+ HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory (httpClient );
80+ return factory ;
7081 }
7182
7283 @ Bean
0 commit comments