1. 程式人生 > >關於 hystrix 的異常 fallback method wasn't found

關於 hystrix 的異常 fallback method wasn't found

llb -s title int http itl man .class comm

典型如下:

@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;
}

這樣就可以解決上述的異常了。

關於 hystrix 的異常 fallback method wasn't found