Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to instantiate [org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder]

I had upgraded Spring Boot version to 3.4.1. I also use spring-cloud-contract-wiremock and httpclient5. I have this RestClient configuration.

ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(requestFactory);
return RestClient.builder().requestFactory(factory)
    .requestInterceptors(interceptors -> interceptors.addAll(
        List.of(new ClientHttpRequestInterceptor(),
            new RequestResponseLoggingInterceptor())))
    .build();

On running application tests, I get this:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder]: Factory method 'clientHttpRequestFactoryBuilder' threw exception with message: org/apache/hc/client5/http/ssl/TlsSocketStrategy

like image 309
venkat snahith Avatar asked May 09 '26 19:05

venkat snahith


1 Answers

This is a problem with the used dependency. I encountered the same issue when running a project made using Springboot Initializr for version 3.4.1. As a fix, I specified the dependency version of httpclient5 to 5.4.1.

If you are using maven as your dependency manager, you can add this to your pom.xml.

<dependency>
    <groupId>org.apache.httpcomponents.client5</groupId>
    <artifactId>httpclient5</artifactId>
    <version>5.4.1</version>
</dependency>
like image 181
Gideon Avatar answered May 11 '26 15:05

Gideon