22
22
23
23
import org .apache .commons .logging .Log ;
24
24
import 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 ;
25
29
import org .apache .hc .core5 .util .Timeout ;
26
30
27
31
import org .springframework .beans .factory .annotation .Value ;
28
32
import org .springframework .boot .SpringApplication ;
29
33
import org .springframework .boot .SpringBootConfiguration ;
30
34
import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
31
- import org .springframework .boot .http .client .ClientHttpRequestFactoryBuilder ;
32
- import org .springframework .boot .http .client .HttpComponentsClientHttpRequestFactoryBuilder ;
33
35
import org .springframework .cloud .client .DefaultServiceInstance ;
34
36
import org .springframework .cloud .loadbalancer .annotation .LoadBalancerClient ;
35
37
import org .springframework .cloud .loadbalancer .core .ServiceInstanceListSupplier ;
36
38
import org .springframework .cloud .loadbalancer .support .ServiceInstanceListSuppliers ;
37
39
import org .springframework .context .annotation .Bean ;
38
40
import org .springframework .http .HttpStatus ;
39
41
import org .springframework .http .ResponseEntity ;
42
+ import org .springframework .http .client .HttpComponentsClientHttpRequestFactory ;
40
43
import org .springframework .web .bind .annotation .GetMapping ;
41
44
import org .springframework .web .bind .annotation .RequestParam ;
42
45
import org .springframework .web .bind .annotation .RestController ;
@@ -62,11 +65,19 @@ public static void main(String[] args) {
62
65
}
63
66
64
67
@ 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 ;
70
81
}
71
82
72
83
@ Bean
0 commit comments