import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Configuration
@Profile("dev")
public class RestTemplateConfigurationDev {
@Bean
public RestTemplate getRestTemplate() {
CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
requestFactory.setConnectTimeout(30000);
requestFactory.setReadTimeout(30000);
requestFactory.setConnectionRequestTimeout(30000);
return new RestTemplate(requestFactory);
}
}
In above code,
requestFactory.setHttpClient(httpClient)
This method is not accepting the CloseableHttpClient object after upgrading to the latest spring boot version.
requestFactory.setReadTimeout(30000);
While this method is deprecated.
Does anybody have an idea on how to fix these issues in spring boot 3.0?