【Bug】Dubbo整合SpringCloud Hystrix --- fallback method wasn't found问题
com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException源代码:/*** @Author: 98* @Date: 2019-8-29 20:23*/@RestControllerpublic class DemoController {@Reference(version =...
·
com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException
源代码:
/**
* @Author: 98
* @Date: 2019-8-29 20:23
*/
@RestController
public class DemoController {
@Reference(version = "${user.service.version}")
private DemoService demoService;
@HystrixCommand(fallbackMethod = "hiHystrix")
@GetMapping("hi/{name}")
public String sayHi(@PathVariable("name") String name){
//return demoService.sayHello(name);
throw new RuntimeException("熔断触发");
}
public String hiHystrix(){
return "Hello Hystrix";
}
}
异常信息:
错误原因
从异常信息可以知道,Hystrix的熔断回调方法无法找到,但是@HystrixCommand(fallbackMethod = “hiHystrix”)也配置了回调的方法名。
最后发现Hystrix熔断回调方法的参数列表需要和熔断方法的参数列表相同,把两个方法的参数列表修改一致即可!!!
/**
* @Author: 98
* @Date: 2019-8-29 20:23
*/
@RestController
public class DemoController {
@Reference(version = "${user.service.version}")
private DemoService demoService;
@HystrixCommand(fallbackMethod = "hiHystrix")
@GetMapping("hi/{name}")
public String sayHi(@PathVariable("name") String name){
//return demoService.sayHello(name);
throw new RuntimeException("熔断触发");
}
public String hiHystrix(@PathVariable("name") String name){
return "Hello Hystrix";
}
}
重新启动服务提供者和服务调用者,通过api方法成功!!
更多推荐
已为社区贡献1条内容
所有评论(0)