ayisha farhin
ayisha farhin

Reputation: 81

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);

Upvotes: 3

Views: 4551

Answers (1)

avvensis
avvensis

Reputation: 955

You should use dependency

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

instead of

implementation 'org.apache.httpcomponents:httpclient'

Upvotes: 4

Related Questions