Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caused by: java.lang.ClassNotFoundException: org.apache.hc.client5.http.classic.HttpClient

To address the same issue as here RestTemplate PATCH request in my spring-boot 3 application

org.springframework.web.client.ResourceAccessException: I/O error on PATCH request for "http://localhost:8080/people/1":Invalid HTTP method: PATCH; nested exception is java.net.ProtocolException: Invalid HTTP method: PATCH

I do things similar as in accepted response:

@Configuration
class TestRestTemplateConfig {

    @Bean
    fun testRestTemplate(restTemplateBuilder: RestTemplateBuilder): TestRestTemplate {
        val testRestTemplate = TestRestTemplate(restTemplateBuilder, null, null, null)
        testRestTemplate.restTemplate.requestFactory = HttpComponentsClientHttpRequestFactory()
        return testRestTemplate
    }
}

Also I have dependency:

implementation("org.apache.httpcomponents:httpclient:4.5.14")

But when I start test I see an error:

Caused by: java.lang.ClassNotFoundException: org.apache.hc.client5.http.classic.HttpClient

But If I try to find this class in my IDE I am able to do it:

enter image description here

I tried to execute command gradle clean but no luck. I am confused.

like image 228
gstackoverflow Avatar asked May 10 '26 17:05

gstackoverflow


1 Answers

The solution is replace

implementation("org.apache.httpcomponents:httpclient:4.5.14")

with

Implementation("org.apache.httpcomponents.client5:httpclient5")
like image 50
gstackoverflow Avatar answered May 12 '26 08:05

gstackoverflow