zoukankan      html  css  js  c++  java
  • hystrix报错找不到相应的fallbackMethod

    1. 问题出现:

    当消费者客户端调用提供者的服务时,会出现以下错误,调用方出现以下错误

    2020-11-27 17:03:51.996 ERROR 11536 --- [p-nio-80-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 : [{"timestamp":"2020-11-27T09:03:51.952+00:00","status":500,"error":"Internal Server Error","trace":"com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't fo... (8286 bytes)]] with root cause
    
    org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 : [{"timestamp":"2020-11-27T09:03:51.952+00:00","status":500,"error":"Internal Server Error","trace":"com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't fo... (8286 bytes)]
        at org.springframework.web.client.HttpServerErrorException.create(HttpServerErrorException.java:100) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
    

    而提供接口服务的一方报的错误如下:

    2020-11-27 17:03:51.937 ERROR 376 --- [nio-8001-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found: processHystrixGetDept([long])] with root cause
    
    com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found: processHystrixGetDept([long])
    

    从上面的报错信息可以看出来 fallback method wasn't found: processHystrixGetDept([long]) ,说明是fallback method 方法有问题,后来发现是Long和long的问题,代码如下:

    @GetMapping("/dept/get/{id}")
        @HystrixCommand(fallbackMethod = "processHystrixGetDept")
        public Dept dept(@PathVariable("id") long id) {
            Dept dept = deptService.queryById(id);
            if (dept == null) {
                throw new RuntimeException("该id" + id + "没有对应的信息");
            }
            return dept;
        }
    
        public Dept processHystrixGetDept(Long id) {
            return new Dept().setDeptno(id)
                    .setDname("该id:" + id + "没有对应的信息,null@HystrixCommand")
                    .setDb_source("没有该数据库信息");
        }
    
    1. 问题解决,定义的备用方法中是Long包装类,但是原始方法中是long基本类型,这就是报错的源头,我将其统一之后就没有报错了
    保持对优秀的热情
  • 相关阅读:
    linux中断子系统
    注释规范
    linux下C获取文件的大小
    oracle 11g 修改内存示例
    联想system sr650安装windows
    iphone 手机音乐制作
    canon dpp 编辑相机raw软件
    浪潮nf5270m5 安装2012
    三种刻录工具及用法
    centos7.5 连接存储配置iscsi
  • 原文地址:https://www.cnblogs.com/luckforefforts/p/14049363.html
Copyright © 2011-2022 走看看