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

典例如下:

@Service

public class OrderService {

@Autowired

RestTemplate restTemplate;

@HystrixCommand(fallbackMethod = "helloError")

public String getOrder(Integer a, Integer b){

return restTemplate.getForObject("http://customer-business-service/show?a="+a+"&b="+b, String.class);

}

public String helloError(){

return "error";

}

}

  

访问出现异常:

com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found: helloError([class java.lang.Integer, class java.lang.Integer])

at com.netflix.hystrix.contrib.javanica.utils.MethodProvider$FallbackMethodFinder.doFind(MethodProvider.java:190) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at com.netflix.hystrix.contrib.javanica.utils.MethodProvider$FallbackMethodFinder.find(MethodProvider.java:159) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at com.netflix.hystrix.contrib.javanica.utils.MethodProvider.getFallbackMethod(MethodProvider.java:73) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at com.netflix.hystrix.contrib.javanica.utils.MethodProvider.getFallbackMethod(MethodProvider.java:59) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.setFallbackMethod(HystrixCommandAspect.java:342) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.access$300(HystrixCommandAspect.java:66) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect$MetaHolderFactory.metaHolderBuilder(HystrixCommandAspect.java:187) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect$CommandMetaHolderFactory.create(HystrixCommandAspect.java:269) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect$MetaHolderFactory.create(HystrixCommandAspect.java:177) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.methodsAnnotatedWithHystrixCommand(HystrixCommandAspect.java:95) ~[hystrix-javanica-1.5.12.jar:1.5.12]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_112]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_112]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_112]

at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_112]

  

这是因为指定的 备用方法 和 原方法 的参数类型,个数不同造成的。需要统一参数列表,修改成:

@Autowired

RestTemplate restTemplate;

@HystrixCommand(fallbackMethod = "helloError")

public String getOrder(Integer a, Integer b){

return restTemplate.getForObject("http://customer-business-service/show?a="+a+"&b="+b, String.class);

}

public String helloError(Integer a, Integer b){

return "error page. params:a="+a+", b="+b;

}

  

这样就可以解决上述异常,正常访问了。

关于hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found异常的更多相关文章

  1. com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found: serviceError([class java.lang.String]) 异常

    在使用spring cloud 的 Hystrix 后可能会遇到 如下截图错误: 后台代码如下: 找了好一会经过分析参数方法和原方法参数步一致造成: 修改后代码如下:

  2. 【spring cloud】子模块启动报错com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect

    spring cloud子模块启动报错 Caused by: java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanic ...

  3. 【spring cloud】spring cloud 使用feign调用,1.fallback熔断器不起作用,2.启动报错Caused by: java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanica.aop.aspectj.Hystri解决

    示例GitHub源码地址:https://github.com/AngelSXD/springcloud 1.首先使用feign调用,需要配置熔断器 2.配置熔断器需要将熔断器注入Bean,熔断器类上 ...

  4. springcloud报错-------关于 hystrix 的异常 FallbackDefinitionException:fallback method wasn't found

    典型如下 第一种import java.util.List;@RestController@RequestMapping("/order")@DefaultProperties(d ...

  5. 解决 spring cloud 项目的 com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect 错误信息

    在项目中引入:引入hystrix依赖,如下 <dependency> <groupId>org.springframework.cloud</groupId> &l ...

  6. java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect

    添加这个依赖 <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId>hystr ...

  7. 使用hystrix监控时出现java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAsp错误,导致无法启动

    解决方法: 添加依赖 <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId>h ...

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

    在 Spring Cloud 中使用断路器 hystrix 后,可能会遇到异常:com.netflix.hystrix.contrib.javanica.exception.FallbackDefin ...

  9. Hint: Fallback method 'public java.lang.String queryUserByIdFallback(java.lang.Long)' must return: User or its subclass

    1.错误日志 熔断器添加错误方法返回时,报了一个 error. com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionExc ...

  10. 停止预览时调用Camera.release(), 出现Method called after release()异常问题原因及解决办法

    如下代码: private void stopPreview() { Log.w(TAG, "stopPreview(), _isPreviewing = " + _isPrevi ...

随机推荐

  1. python数据结构的性能分析

    2.python数据结构的性能分析 一.引言 - 现在大家对 大O 算法和不同函数之间的差异有了了解.本节的目标是告诉你 Python 列表和字典操作的 大O 性能.然后我们将做一些基于时间的实验来说 ...

  2. flask 中的request【转载】

    每个框架中都有处理请求的机制(request),但是每个框架的处理方式和机制是不同的,为了了解flask的request中都有什么东西,首先我们要写一个前后端的交互 基于HTML+Flask 写一段前 ...

  3. VMware与Windows主机之间复制粘贴

    其实就是安装VMware Tools,但不知道为什么我的VMware Workstation不能安装VMware Tools,记得之前有次安装过,但是失败了. 基于apt-get命令下载安装其实是更好 ...

  4. 将ipynb文件转成pdf

    本文内容:将GitHub上ipynb源码格式的书籍转成pdf 应用场景:GitHub上某些书籍按章节使用ipynb格式存储 (Jupyter创建了一种良好的交互方式,即将程序说明和代码放在同一个文档中 ...

  5. 【ElementPlus】el-form使用技巧:动态切换校验规则的最佳实践

    喵~ 今天分享一篇在 ElementPlus 中使用 el-form 动态切换校验规则 的实用方法. 一.问题概述 作为前端开发人员,在开发项目中,特别是后台管理系统,表单的使用是必不可少的.当业务需 ...

  6. orangepi zero3 使用dd命令进行SD卡系统备份与还原

    1. 使用dd命令备份整个sd卡 首先使用 df -h命令查看sd卡挂载名,如下所示,sd卡挂载为 /dev/sdc meng@meng:~/桌面/code$ df -h 文件系统 大小 已用 可用 ...

  7. R机器学习:特征工程与特征选择的介绍

    两个月没更新了,没有其它理由,就是懒惰,间接持续性的懒惰,一直持续了2个月,简直懒惰!!!大家的好多的私信也没回就过期回不了了.请大家批评我!!!. 看了很多高深的算法之后,实在是看不太明白,所以今天 ...

  8. 特性Attribute的简单用法

    一.建立一个自定义的Attribute类 注:类名+Attribute,类需要继承Attribute /// <summary> /// 特性 /// </summary> p ...

  9. 【前端】2024年 前端Base64编码的中文处理问题

    window.btoa() 遇到中文要出问题 localStorage.setItem("token",window.btoa(unescape(encodeURIComponen ...

  10. shell 获取 目录名 当前目录名

    Four ways to extract the current directory name By  Sergio Gonzalez Duran on November 06, 2007 (9:00 ...