记录 feignclient 回退异常

问题描述 投票:0回答:1

Fallback 是 Feignclient 中的一个很酷的功能,但是我想知道在 fallback 事件期间会发生什么。无论如何输出根本原因到日志文件?

spring-boot fallback spring-cloud-feign
1个回答
0
投票

也许,您可以使用

fallbackFactory
中的
@FeignClient
属性,它可以访问导致回退触发的原因。

@FeignClient(name = "hello", fallbackFactory = HystrixClientFallbackFactory.class)
protected interface HystrixClient {
    @RequestMapping(method = RequestMethod.GET, value = "/hello")
    Hello iFailSometimes();
}

@Component
static class HystrixClientFallbackFactory implements FallbackFactory<HystrixClient> {
    @Override
    public HystrixClient create(Throwable cause) {
        return new HystrixClient() {
            @Override
            public Hello iFailSometimes() {
                return new Hello("fallback; reason was: " + cause.getMessage());
            }
        };
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.