FallbackDefinitionException:fallback method wasn't found: defaultUser([class java.lang.Long])
来源:互联网 发布:虚拟号码发短信软件 编辑:程序博客网 时间:2024/06/06 09:42
在《spring cloud 微服务实战》第155页至156页,服务降级这一部分,定义服务降级的方式要根据你的请求命令实现方式,如果你是通过继承HystrixCommand来创建请求命令的,那么服务降级就可以通过重写getFallback()方法来实现:
public class UserCommand extends HystrixCommand<User>{ private RestTemplate restTemplate; private Long id; public UserCommand(Setter setter,RestTemplate restTemplate,Long id){ super(setter); this.restTemplate=restTemplate; this.id=id; } @Override protected User run() throws Exception { return restTemplate.getForObject("http://localhost:8081/users/{1}",User.class,id); } @Override protected User getFallback() {//重写服务降级方法 return new User(3,"test"); }}
如果通过注解@HystrixCommand的方式来实现的话,服务降级就要在注解中添加fallbackMethod参数来指定具体的服务降级实现方法:
@Servicepublic class UserService { @Autowired RestTemplate restTemplate; @HystrixCommand(fallbackMethod = "defaultUser") public User getUserById(Long id){ Integer.parseInt("wd"); return restTemplate.getForObject("http://USER-SERVICE/users/{1}",User.class,id); } public User defaultUser(Long id){//书上这里少了参数 return new User(4,"gg"); }我没用过旧版本的springcloud(例如Angel、Brixton),不知道是不是旧版本在指定服务降级方法时就可以不带参数呢?(我没验证过),还是作者忘了?反正你如果用的是Dalston版本,这里的defaultUser方法如果和getUserById方法参数不一致的话会报错:com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException:
fallback method wasn't found: defaultUser([class java.lang.Long])
阅读全文
0 0
- FallbackDefinitionException:fallback method wasn't found: defaultUser([class java.lang.Long])
- 关于 hystrix 的异常 fallback method wasn't found
- 关于 hystrix 的异常 fallback method wasn't found
- java.lang.IllegalArgumentException: At least one handler method must be found in class [class SayThr
- java.lang.IllegalStateException: focus search returned a view that wasn't able to take focus!
- java.lang 类 Class<T>
- 解决Pandoc wasn't found.pdflatex not found on PATH
- java.lang.UnsatisfiedLinkError: Native method not found
- java.lang.UnsatisfiedLinkError: Native method not found
- java.lang.UnsatisfiedLinkError: Native method not found
- J2ME Class Not Found java/lang/ClassNotFoundException
- DWR:java.lang.SecurityException: Class not found
- java.lang.InstantiationException: can't instantiate class
- Expected: class java.lang.Long, got class java.lang.Integer异常处理
- Cannot convert 0:0 of type class java.lang.String to class java.lang.Long
- Cannot convert 临时用户 of type class java.lang.String to class java.lang.Long
- Class t = Class.forName("java.lang.Thread");
- java.lang.UnsatisfiedLinkError: Native method not found问题
- 7.27-8.2 JLL实习日志-Ajax +Restful+Api+Variable参数
- ThreadLocal详解
- 关于我们
- HDU 6058 Kanade's sum (区间第k大的数的贡献)
- 偏差-方差权衡(Bias-Variance Tradeoff)
- FallbackDefinitionException:fallback method wasn't found: defaultUser([class java.lang.Long])
- 一起学Kotlin(3)
- params ref out
- jquery 基本过滤器,删除table的行
- JDBC配置文件properties
- HTTP中GET方法和POST方法的区别
- redis 集群
- Android中使EditText失去焦点,edittext禁止弹出键盘
- 欢迎使用CSDN-markdown编辑器