【SpringBoot学习笔记】运行错误:No fallback instance of type class found for feign client

[[报错情况:]]

feign中使用Hystrix,报错:No fallback instance of type class  found for feign client 

[源码:]

@FeignClient(value = "eureka-client", configuration = FeignConfig.class, fallback = HiHystrix.class)
public interface EurekaClientFeign {
@GetMapping(value = "/hi")
String sayHiFromClientEureka(@RequestParam(value = "name") String name);
}

@Component
public class HiHystrix implements EurekaClientFeign {
@Override
public String sayHiFromClientEureka(String name) {
return "hi," + name + ",sorry,error!";
}
}

[[原因和解决办法:]]
“HiHystrix”类实现“EurekaClientFeign”接口时,缺少注解“@Component”,导致编译时未将“HiHystrix”类自动实例化,当服务接口不可用时,进入到熔断器fallback的逻辑处理中,此时检查不到对应的实例,将无法使用,因此虽然编译器没检查到语法错误但运行时报错。

猜你喜欢

转载自www.cnblogs.com/zuixieyang/p/9211932.html