在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. Linux系统进程

    系统进程 [1].进程基本概述 当我们运行一个程序,那么我们将运行的程序叫进程 ​ PS1:当程序运行为进程后,系统会为该进程分配内存,以及进程运行的身份和权限 ​ PS2:在进程运行的过程中,服务器 ...

  2. Android运行时请求权限封装

    @ 目录 1 介绍 2 测试用例设计 3 实现 4 用例测试 5 总结 本文目的:"借助透明Activity封装一个易于调用的权限请求模块" 1 介绍 Android权限的校验和申 ...

  3. ZCMU-1149

    就是背包01问题 #include<iostream> #include<cstring> /*01背包问题*/ using namespace std; const int ...

  4. 在app內建web server

    这几年在三家企业都使用 app 內建 web server 的技术方案.效果很好. 该方案顾名思义,就是在 app 中加入一个 embed webserver 组件.组件和app运行于同一进程空间.程 ...

  5. 【MySQL】求和查询,目标值int,但空数据时返回null的问题(Java)

    问题分析 int selectDeviceMonthRepairCount(String deviceType, String month); <select id="selectDe ...

  6. 【C#】根据分数求出相应的成绩等级

    设计窗体程序,使用文本框控件输入百分制成绩,实现将学生的百分制成绩转换为对应的等级成绩(优.良.中.及格.不及格). 要求:必须使用异常处理技术,优先使用switch-case的方式 点击查看代码 | ...

  7. 【Web前端】【疑难杂症】轮播图图片自适应显示问题(bootstrap3轮播图)

    关键代码 html <!-- 轮播图开始--> <div id="header" class="carousel slide"> < ...

  8. 若依管理系统 -- 更换头像上传文件报错(/tmp/tomcat.8013579853364800617.8080/work/Tomcat/localhost/ROOT)

    一.错误情况 1.错误截图 二.错误解决情况 1.若依官方解答的链接 2.若依解答原文 1)原因: 在linux系统中,springboot应用服务再启动(java -jar 命令启动服务)的时候,会 ...

  9. Ubuntu中文件夹建立软链接方法

    1:预备知识 -s 是代号(symbolic)的意思. 这里有两点要注意:第一,ln命令会保持每一处链接文件的同步性,也就是说,不论你改动了哪一处,其它的文件都会发生相同的变化:第二,ln的链接又软链 ...

  10. Qt开发经验小技巧91-100

    数据库处理一般建议在主线程,如果非要在其他线程,务必记得打开数据库也要在那个线程,即在那个线程使用数据库就在那个线程打开,不能打开数据库在主线程,执行sql在子线程,很可能出问题. 新版的QTcpSe ...