Spring Cloud 关于 hystrix 的异常 fallback method wasn't found

时间:2025-04-08 09:35:13

在 Spring Cloud 中使用断路器 hystrix 后,可能会遇到异常:com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found

典型如下:

@HystrixCommand(fallbackMethod = "fallbackHi")
public String getHi(String x) {
String msg = restTemplate.getForObject("http://jack/hi", String.class);
return msg;
} public String fallbackHi(){
return "can't say hi";
}

这样就会出现如上所述的异常,这是因为指定的 备用方法 和 原方法 的参数个数,类型不同造成的;

所以需要统一参数的个数,类型:

@HystrixCommand(fallbackMethod = "fallbackHi")
public String getHi(String x) {
String msg = restTemplate.getForObject("http://jack/hi", String.class);
return msg;
} public String fallbackHi(String x){
return "can't say hi, and get: " + x;
}

这样就可以解决上述的异常了。

版权声明:本文为博主原创文章,未经博主允许不得转载;嘿嘿。 http://blog.****.net/Ezreal_King/article/details/72942823