Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i define a Hystrix Client Fallback directly in a @FeignClient

I'm tring to define my fallback function directly in the feign defenition as described in the spring documentation, Please see the code below, but i get an error that i can't define a static class " modifier static not allowed here". How can i get the fallback function to run when feign call fails?

Regards,

Nadav

@FeignClient(name = "hello", fallback = HystrixClientFallback.class)

protected interface HystrixClient {

@RequestMapping(method = RequestMethod.GET, value = "/hello")

     Hello iFailSometimes();

}

static class HystrixClientFallback implements HystrixClient {

@Override

public Hello iFailSometimes() {

return new Hello("fallback");

}

}
like image 700
Nadav Sharabi Avatar asked Jan 06 '23 16:01

Nadav Sharabi


1 Answers

Adding @Component to the top of the class worked for me.

@Component
class HystrixClientFallback implements HystrixClient {

    @Override
    public Hello iFailSometimes() {
        return new Hello("fallback");
    }

}
like image 144
Adinarayana Mutyala Avatar answered Jan 09 '23 07:01

Adinarayana Mutyala