• 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基本类型,这就是报错的源头,我将其统一之后就没有报错了
    保持对优秀的热情
  • 相关阅读:
    Nhibernate初学
    TSQL笔记
    Java是剑客飘逸;.NET是刀客霸道 (一) 【转载】
    在datagrid中求和(vb.net,c#)
    Java牢骚之我见(转载)
    Java是剑客飘逸;.NET是刀客霸道 (二) 【转载】
    可可西里观后感(转)保护藏羚羊
    .net快速入门方法,转csdn
    手工添加“显示桌面”快捷方式
    过年128>24
  • 原文地址:https://www.cnblogs.com/luckforefforts/p/14049363.html
Copyright © 2020-2023  润新知