在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. Java深度历险(一)——Java字节代码的操纵

    [编者按]Java作为业界应用最为广泛的语言之一,深得众多软件厂商和开发者的推崇,更是被包括Oracle在内的众多JCP成员积极地推动发展.但是对于Java语言的深度理解和运用,毕竟是很少会有人涉及的 ...

  2. git针对指定网站设置代理

    我们经常要用到各种git地址,比如github.gitee还有自己搭建的git等等. 但是github我们经常拉取和推送代码的时候超时,这时候如果我们搜索会发现大量的文章都是告诉我们设置全局系统代理: ...

  3. linux模拟HID USB设备及wireshark USB抓包配置

    目录 1. 内核配置 2. 设备配置 附 wireshark USB抓包配置 笔者开发USB设备时的一些记录 1. 内核配置 内核启用USB Gadget,使用fs配置usb device信息. De ...

  4. 简单理解Linux File的操作

    类Unix系统是支持多个进程打开同一个文件,进行读写. 得益于类Unix系统对于文件操作的特殊设计. 分为三个数据结构 进程表项:其中包含进程中打开的文件和设备的文件描述符.还包含该文件描述符对应的文 ...

  5. Ubuntu下xrdp登陆故障解决方案

    故障描述: Ubuntu使用xrdp远程桌面运行一段时间后,出现登陆错误: xrdp_mm_process_login_response: login failed 原因分析: 远程桌面没有正确关闭所 ...

  6. Prometheus 3.0.0 升级中遇到的 `--storage.tsdb.retention` 错误的修复方法

    在将 Prometheus 升级到 3.0.0 后,许多用户会遇到以下错误: Error parsing command line arguments: unknown long flag '--st ...

  7. 【Amadeus原创】Docker安装Nginx,并配置端口转发,配置SSL

    1,docker安装Nginx [root@hecs-29489 ~]# docker pull nginx Using default tag: latest latest: Pulling fro ...

  8. IOS中的Context Menu

    IOS中的Context Menu 通过长按组件或者3D touch方式,周边全部虚化,弹出一个可操作的菜单,并且菜单之间也可以嵌套 IOS13之后已经弃用UIViewControllerPrevie ...

  9. 巧用mask属性创建一个纯CSS图标库

    说明 mask 是CSS中的一个属性,它允许开发者在元素上设置图像作为遮罩层.这个属性的强大之处,在于它可以接受多种类型的值,包括关键字值.图像值.渐变色,甚至可以设置多个属性值. SVG(Scala ...

  10. Nginx https证书生成

    一.证书和私钥的生成 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 1.创建服务器证书密钥文件 server.key: ...