我希望直接在假装防御中定义我的后备功能,如春季文档中所述,请参阅下面的代码,但是我得到一个错误,我无法定义静态类&# 34;修饰符静态不允许在这里"。当假装呼叫失败时,如何让后备功能运行?
此致
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");
}
}
答案 0 :(得分:7)
将@Component
添加到课程顶部为我工作。
@Component
class HystrixClientFallback implements HystrixClient {
@Override
public Hello iFailSometimes() {
return new Hello("fallback");
}
}