zoukankan      html  css  js  c++  java
  • Spring Cloud 关于 hystrix 的异常 fallback method wasn't found

    在 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.csdn.net/Ezreal_King/article/details/72942823
  • 相关阅读:
    uva11021
    WC2019退役失败记
    北大集训2018垫底记
    NOI后训练记录
    NOI2018垫底记
    NOI前训练记录
    JSOI2018R2游(afo)记
    HNOI(AHOI)2018游记
    JSOI2018R1(九省联考)游(afo)记
    LR 8 Hello 戊戌
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/8611095.html
Copyright © 2011-2022 走看看