0

I have this piece of code in my program:

this.restTemplate = restTemplateBuilder
                .requestFactory(new HttpComponentsClientHttpRequestFactory());

but I have this compilation error

Cannot resolve method 'requestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory)'

Even the method expects this:

 public RestTemplateBuilder requestFactory(Class<? extends ClientHttpRequestFactory> requestFactory) 

and the class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean

Sandro Rey
  • 2,429
  • 13
  • 36
  • 80
  • 1
    The parameter is expected to be the `Class` object of the factory. Not the instance of the factory as you're trying to pass in. – Kayaman May 22 '20 at 09:15

1 Answers1

0

Try this way

HttpClientBuilder clientBuilder = HttpClientBuilder.create();
HttpClient httpClient = clientBuilder.build();
restTemplatebuilder.requestFactory(() -> { return new HttpComponentsClientHttpRequestFactory(httpClient);});
Eklavya
  • 17,618
  • 4
  • 28
  • 57