关于hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found异常
在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异常的更多相关文章
- com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found: serviceError([class java.lang.String]) 异常
在使用spring cloud 的 Hystrix 后可能会遇到 如下截图错误: 后台代码如下: 找了好一会经过分析参数方法和原方法参数步一致造成: 修改后代码如下:
- 【spring cloud】子模块启动报错com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect
spring cloud子模块启动报错 Caused by: java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanic ...
- 【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,熔断器类上 ...
- springcloud报错-------关于 hystrix 的异常 FallbackDefinitionException:fallback method wasn't found
典型如下 第一种import java.util.List;@RestController@RequestMapping("/order")@DefaultProperties(d ...
- 解决 spring cloud 项目的 com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect 错误信息
在项目中引入:引入hystrix依赖,如下 <dependency> <groupId>org.springframework.cloud</groupId> &l ...
- java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect
添加这个依赖 <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId>hystr ...
- 使用hystrix监控时出现java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAsp错误,导致无法启动
解决方法: 添加依赖 <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId>h ...
- Spring Cloud 关于 hystrix 的异常 fallback method wasn't found
在 Spring Cloud 中使用断路器 hystrix 后,可能会遇到异常:com.netflix.hystrix.contrib.javanica.exception.FallbackDefin ...
- 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 ...
- 停止预览时调用Camera.release(), 出现Method called after release()异常问题原因及解决办法
如下代码: private void stopPreview() { Log.w(TAG, "stopPreview(), _isPreviewing = " + _isPrevi ...
随机推荐
- Docker:查看当前登录用户和密码
一.查看 查看所有 docker 服务器登陆的用户和密码. # Linux cat /root/.docker/config.json # Windows C:\Users\Name\.docker\ ...
- Spring IOC、DI、AOP原理和实现
(1)Spring IOC原理 IOC的意思是控件反转也就是由容器控制程序之间的关系,把控件权交给了外部容器,之前的写法,由程序代码直接操控,而现在控制权由应用代码中转到了外部容器,控制权的转移是 ...
- Integrating JDBC with Hibernate
One of the powerful things about Hibernate is that you do not typically need to manually write SQL: ...
- Java8 Lambda编程常用技巧
遍历打印List List<Integer> list= Arrays.asList(1,5,6,8,9,32,5,8,7,4,5); list.forEach(System.out::p ...
- 基于 C# 编写的 Visual Studio 文件编码显示与修改扩展插件
前言 在软件开发过程中,尤其是在处理跨平台或来自不同来源的项目时,文件的编码格式往往会成为一个不可忽视的问题.不同的操作系统.编程语言和编辑器可能对文件编码有不同的支持和默认设置,这可能导致在打开一个 ...
- NET任务调度框架Hangfire使用指南
Hangfire 是一个开源的 .NET 任务调度框架,它允许开发人员轻松地将长时间运行的任务.定时任务和其他后台处理从主线程中分离出来,以提高应用程序的响应速度和性能 1. 安装 Hangfire ...
- Java并发 —— 线程并发(二)
Java 锁 Java 中的锁是在多线程环境下,保证共享资源健康,线程安全的一种手段 线程操作某个共享资源之前,先对资源加一层锁,保证操作期间没有其他线程访问资源,操作完成后再释放锁 保持数据一致 ...
- Qt 子窗口 隐藏标题栏的图标,在任务栏上的不显示
Qt子窗口使用Qt::Dialog样式时,隐藏窗口标题栏图标方法: this->setWindowIcon(QIcon()); Qt子窗口,在任务栏上的不显示,最简单的方法是设置Qt::Tool ...
- 【巧用set实现对有序数组O(logn)时间复杂度增、删、查、改、二分操作】codeforces 1041 C. Coffee Break
题意 第一行输入三个整数 \(n,m,d(1 \leq n \leq 2 * 10^5, n \leq m \leq 10^9, 1 \leq d \leq n)\),第二行输入 \(n\) 个整数, ...
- 开启Word、Excel、PPT时速度很慢的一种解决方法
本文介绍基于修改加载项,解决Microsoft Office系列软件开启速度较慢的办法. 最近,发现Excel软件的打开速度越来越慢,会在一定程度上影响工作效率.因此尝试对此加以解决.其中,本 ...