Feign Fallback is not working with Springboot 2.7.11

267 views Asked by At

After Migrating the spring boot version from 2.0.8.RELEASE to 2.7.11 the feign fallback is not working.

facing below error org.springframework.web.util.NestedServletException: Request processing failed; nested exception is feign.FeignException$InternalServerError: [500 Internal Server Error] during [GET] to [https://sampleurl/test] []: [Apache Tomcat/7.0.39 - Error report<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans... (1177 bytes)]

I am using below code

@FeignClient(name = "myFeign", fallbackFactory = MyFeignClientFallbackFactory.class)
public interface MyFeignClient {
     @RequestMapping(value = "/test", method = RequestMethod.GET, consumes = MediaType.APPLICATION_ATOM_XML_VALUE,produces = MediaType.APPLICATION_XML_VALUE)
    String getValue(@RequestParam("param1") String param1);
}

fallback factory class

@Component
public class MyFeignClientFallbackFactory implements FallbackFactory<MyFeignClientFallback> {

    @Override
    public MyFeignClientFallback create(Throwable cause) {
        return new MyFeignClientFallback(cause);
    }

}

Fallback class


@Slf4j
public class MyFeignClientFallback implements MyFeignClient{

    
    private final Throwable cause;

    public MyFeignClientFallback(Throwable cause) {
        this.cause = cause;
    }

    @Override
    public String getValue(String param1) {
        mapErrorResponse("param1");
        return null;
    }
   private void mapErrorResponse(String methodName) {
        log.error("Error while calling feign method " + methodName);
    }

I am using springboot 2.7.11 with java 11 and spring cloud 2021.0.1 version

dependencies for feign client

<dependency>
<groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-openfeign</artifactId>
 <version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
  <version>2.2.10.RELEASE</version>
 </dependency>
0

There are 0 answers