Spring Open Feign fallbackFactory not working

73 views Asked by At

I have upgraded my java project from java 8 to java 21. Below my pom.xml file

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.17</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
     <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>21</java.version>
        <jacoco.version>0.8.11</jacoco.version>
        <spring-cloud.version>2021.0.8</spring-cloud.version>
        <spring-boot-starter-version>2.7.17</spring-boot-starter-version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        ---
        </dependencies>
@FeignClient(name = "LServiceClient", url = "${abc}", configuration = FeignConfig.class,
        fallbackFactory = LServiceClientFallback.class)
public interface LServiceClient {
    @RequestMapping(method = RequestMethod.GET, value = "url")
    ResponseEntity<LDetails> getLDetails(@PathVariable("id") UUID id);
}



@Component
@Slf4j
public class LServiceClientFallback implements FallbackFactory<LServiceClient> {
    @Override
    public LServiceClient create(Throwable cause) {
        return new LServiceClient() {
            @Override
            public ResponseEntity<LDetails> getLDetails(UUID id) {
                if (((FeignException) cause).status() == 404) {
                    log.error("Not able to find L account mapping for:" + id, cause);
                    return new ResponseEntity<>(HttpStatus.NOT_FOUND);
                }                
                return new ResponseEntity<>(HttpStatus.BAD_GATEWAY);
            }
        };
    }
}

After java and spring upgrade y fallbackFactory stopped working

Below properties are present in application.properties file

feign.hystrix.enabled=true
feign.client.config.default.connectTimeout=10000
feign.client.config.default.readTimeout=50000
hystrix.command.default.execution.timeout.enabled=true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000

When the feign client gives 404, it is not going inside FallbackFactory. It used to work before spring upgrade.

0

There are 0 answers