10

Context

I have a spring boot (version 2.2.6.RELEASE) web project.

From this web application (I call "APP1") I want to call another URI using the PATCH method from another web application (Let's call it "APP2"). In my pom.xml, I have the following dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

Here is how I call the PATCH method of the other web application.

@FeignClient(name = "clientName", url = "base-uri")
public interface MyInterface{
   @PatchMapping(value = "/target-uri")
    void callClientMethod(Map<String, Object> args);

Problem

  • The APP2's PATCH method is effectively being called
  • But then APP1 throws the following error:
    • feign.RetryableException: Invalid HTTP method: PATCH executing PATCH

I looked on the Internet for a solution, and added the following snipet to my pom.xml

<dependency>
    <groupId>com.netflix.feign</groupId> <!-- Also tried io.github.openfeign -->
    <artifactId>feign-httpclient</artifactId>
    <version>8.18.0</version>
</dependency>

After that, APP2's PATCH method is stille properly called but in APP1 I got the following error : java.lang.NoSuchMethodError: feign.Response.create(ILjava/lang/String;Ljava/util/Map;Lfeign/Response$Body;)Lfeign/Response;

Question

  • Does anyone know how to solve this error ?

Thanks in advance for your help !

4 Answers 4

29

I had the same problem and spent a lot of time for understand and resolve this problem.
First what you need to understand that is the Feign doesn't support PATCH http method for call from the box!
And if you can change methods in both services use PUT for update instead PATCH...

But if you integrate with third party implementation you should add some configurations:
1. Add dependency which support PATCH http method:

// https://mvnrepository.com/artifact/io.github.openfeign/feign-okhttp
compile group: 'io.github.openfeign', name: 'feign-okhttp', version: '10.2.0'

  1. Add configuration:
@Configuration 
public class FeignConfiguration {
    @Bean
    public OkHttpClient client() {
        return new OkHttpClient();
    } 
}
  1. And example for PATCH request with Feign:
@FeignClient(name = "someapi", url = "${client.someapi.url}")
@Component
@RequestMapping("/users")
public interface SomeClient {

    @RequestMapping(value = "/{id}",
            method = RequestMethod.PATCH,
            consumes = MediaType.APPLICATION_JSON_VALUE,
            produces = MediaType.APPLICATION_JSON_VALUE)
    FeignUser update(@PathVariable("id") Long id, @RequestBody Map<String, Object> fields);
}

Hope it helps someone.

4
  • 2
    This should be the accepted answer. Had a same problem and this solved it Aug 27, 2020 at 6:33
  • 1
    This works, thank you. My project is spring-cloud-openfeign - 2.1.0.RELEASE and feign-okhttp - 10.12.
    – Grisotto
    Mar 9, 2021 at 14:47
  • How we support SSL in this case? I don't see anyway to setup SSLSocketFactory in OkHttpClient
    – Nghia Do
    Oct 27, 2021 at 17:58
  • This solution doesn't work for me. Jay Ehsaniara's solution works for me. Sep 27, 2022 at 6:59
9

Just Add:

<dependency>
     <groupId>io.github.openfeign</groupId>
     <artifactId>feign-httpclient</artifactId>
</dependency>
4
  • 2
    That is not sufficient by itself, you also need to provide feign.httpclient.enabled: true.
    – Shannon
    Aug 3, 2021 at 21:15
  • 1
    Also, if you prefer to use Apache httpclient5, you can depend on io.github.openfeign:feign-hc5 instead, and provide feign.httpclient.hc5.enabled: true
    – Shannon
    Aug 3, 2021 at 21:17
  • Adding this dependency it fails the application with: Unsatisfied dependency expressed through method 'connectionManager' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.commons.httpclient.ApacheHttpClientConnectionManagerFactory' available Aug 26, 2022 at 12:14
  • This is to upvote @Shannon's comment. From the docs, "Starting with Spring Cloud OpenFeign 4, the Feign Apache HttpClient 4 is no longer supported. We suggest using Apache HttpClient 5 instead." So io.github.openfeign:feign-hc5 provided with feign.httpclient.hc5.enabled: true is the go-to solution for newer versions of OpenFeign.
    – Sam S
    Feb 23 at 12:48
1

If you are adding Feign with the following dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId> <!-- has dependecy on spring-cloud-openfeign-core inside, which already maintains version of feign-okhttp artifact -->
</dependency>

you can add okhttp client (without hardcoding artifact version) to fix the issue with PATCH request:

<dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-okhttp</artifactId> <!-- Required to use PATCH -->
</dependency>

No other steps needed. The okhttp client will be applied automatically by auto configuration.

Also, this way you don't need to manage feign-okhttp artifact version. Spring Cloud will manage version for you.

Tested with Spring Boot 2.7.6

1
  • 1
    Works well with spring boot 2.2.8.RELEASE and feign 2.2.1.RELEASE
    – amisiuryk
    Mar 9 at 12:50
-1

The following config works for me:

<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-jackson</artifactId>
    <version>${feign.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-httpclient</artifactId>
    <version>${feign.version}</version>
</dependency>

Where:

feign.version - 11.0
Spring Boot - 2.3.0.RELEASE
Spring-cloud.version - 2.2.3.RELEASE

1
  • It doesn't work. When i added this dependencies i receive InvocationTargetException for all my feign method calls(GET/PUT/POST). Aug 25, 2020 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.