Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 3 RestTemplate-HttpComponentsClientHttpRequestFactory incomaptible with org.apache.http.client.HttpClient

HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);

'HttpComponentsClientHttpRequestFactory(org.apache.hc.client5.http.classic.HttpClient)' in 'org.springframework.http.client.HttpComponentsClientHttpRequestFactory' cannot be applied to '(org.apache.http.client.HttpClient)'

Need solution to solve this in any other alternative way.

Constructing HttpClient of package

import io.micrometer.core.instrument.binder.httpcomponents.PoolingHttpClientConnectionManagerMetricsBinder;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
HttpClient httpClient = HttpClientBuilder
        .create().setConnectionManager(connectionManager)
        .build();
new PoolingHttpClientConnectionManagerMetricsBinder(connectionManager, "my-pool").bindTo(registry);
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
like image 325
ayisha farhin Avatar asked Jun 25 '26 06:06

ayisha farhin


1 Answers

You should use dependency

implementation 'org.apache.httpcomponents.client5:httpclient5'

instead of

implementation 'org.apache.httpcomponents:httpclient'

like image 182
avvensis Avatar answered Jun 27 '26 21:06

avvensis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!