requestFactory(Class<? extends ClientHttpRequestFactory>) in the type RestTemplateBuilder is not applicable

The requestFactory method takes either the class, or a Supplier<ClientHttpRequestFactory> so you need to do either:

.requestFactory(HttpComponentsClientHttpRequestFactory.class)

or

.requestFactory(() -> new HttpComponentsClientHttpRequestFactory(client))

Presumably the latter, since you want to pass in client.


The below method works fine till spring boot 1.x

.requestFactory(new HttpComponentsClientHttpRequestFactory(client))

but in later version of spring boot like 2.x you need to change it to -

.requestFactory(HttpComponentsClientHttpRequestFactory.class)

or

.requestFactory(() -> new HttpComponentsClientHttpRequestFactory(client))