在 Spring Cloud 中使用断路器 hystrix 后,可能会遇到异常:com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found
典型如下:
复制代码
1
2
@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"; }
这样就会出现如上所述的异常,这是因为指定的 备用方法 和 原方法 的参数个数,类型不同造成的;
所以需要统一参数的个数,类型:
复制代码
1
2
@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
- 本文已收录于以下专栏:
- Spring Cloud 小手册
转载于:https://www.cnblogs.com/hfultrastrong/p/8611095.html
最后
以上就是刻苦手链最近收集整理的关于Spring Cloud 关于 hystrix 的异常 fallback method wasn't found的全部内容,更多相关Spring内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复