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:
I tried to execute command gradle clean
but no luck. I am confused.
The solution is replace
implementation("org.apache.httpcomponents:httpclient:4.5.14")
with
Implementation("org.apache.httpcomponents.client5:httpclient5")