典型如下

第一种

import java.util.List;

@RestController
@RequestMapping("/order")
@DefaultProperties(defaultFallback = "fallback4Wait")
public class OrderController {

@Autowired
private RestTemplate restTemplate;

@HystrixCommand(commandProperties = {
@HystrixProperty(name="circuitBreaker.requestVolumeThreshold",value = "10"),
@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds",value = "10000"),
@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage",value = "60")
})
@RequestMapping(value = "/buy/{id}",method = RequestMethod.GET)
public Product findById(@PathVariable Long id){

if (id % 2 == 0 ) {
throw new RuntimeException("") ;
}

return restTemplate.getForObject("http://PRODUCT-SERVICE/product/"+ id,Product.class);

}

/**
* 回退方法的返回值必须与调用者的方法要一致,参数也要完全一致
* @param id
* @return
*/
public Product fallback4Wait(){ // 此处应该没有参数
Product product = new Product();
product.setProductName("当前服务访问压力过大,请稍后重试");
return product;
}
}

----------------------------------------
第二种

import java.util.List;

@RestController
@RequestMapping("/order")
@DefaultProperties(defaultFallback = "fallback4Wait")
public class OrderController {

@Autowired
private RestTemplate restTemplate;

@Autowired
private DiscoveryClient discoveryClient; // 服务发现类

@HystrixCommand(fallbackMethod = "fallback4Wait")
@RequestMapping(value = "/buy/{id}",method = RequestMethod.GET)
public Product findById(@PathVariable Long id){

if (id % 2 == 0 ) {
throw new RuntimeException("") ;
}

return restTemplate.getForObject("http://PRODUCT-SERVICE/product/"+ id,Product.class);

}

/**
* 回退方法的返回值必须与调用者的方法要一致,参数也要完全一致
* @param id
* @return
*/
public Product fallback4Wait(Long id){ // 此处有参数与上面一致
Product product = new Product();
product.setProductName("当前服务访问压力过大,请稍后重试");
return product;
}
}
  1. @HystrixCommand(fallbackMethod = "fallbackHi")
  2.  
    public String getHi(String x) {
  3.  
    String msg = restTemplate.getForObject("http://jack/hi", String.class);
  4.  
    return msg;
  5.  
    }
  6.  
     
  7.  
    public String fallbackHi(){
  8.  
    return "can't say hi";
  9.  

springcloud报错-------关于 hystrix 的异常 FallbackDefinitionException:fallback method wasn't found的更多相关文章

  1. SpringCloud报错:Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing MappingNode

    今天在配置eureka集群时,SpringCloud报错如下: Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing ...

  2. SpringCloud报错:Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

    今天启动用eureka的服务消费者时,一直出现问题. SpringCloud报错: Caused by: org.springframework.context.ApplicationContextE ...

  3. SpringCloud报错: "Field discoveryClient in com.controller.DcController required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found."

    SpringCloud报错: "Field discoveryClient in com.controller.DcController required a bean of type 'c ...

  4. Xcode报错Expected selector for Objective-C and Expected method body

    昨天把键盘拿起来拍一下清清灰,然后就发现Xcode报错了,Xcode报错Expected selector for Objective-C and Expected method body,也不知道什 ...

  5. springcloud报错集合

    springcloud启动报错Connection refused: connect 参考:https://blog.csdn.net/deemo__/article/details/78932401 ...

  6. python中如何通过报错信息定位问题(异常传播轨迹)

    class SelfException(Exception): pass def main(): firstMethod() def firstMethod(): secondMethod() def ...

  7. springcloud报错:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'armeriaServer' defined in class path resource

    spring boot配置zipkin 无法启动 加入 Zipkin Server 由于需要收集 Spring Cloud 系统的跟踪信息,以便及时地发现系统中出现的延迟升高问题并找出系统性能瓶颈的根 ...

  8. Springcloud报错:java.lang.IllegalStateException: Service id not legal hostname (/a-service)

    今天在做springcloud链路追踪的时候,报错java.lang.IllegalStateException: Service id not legal hostname (/a-service) ...

  9. SpringCloud报错:com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

    启动SpringCloudEureka 报错:com.netflix.discovery.shared.transport.TransportException: Cannot execute req ...

随机推荐

  1. Linux常用命令整理:文件目录管理

    据说,你要对Linux文件做的事情,98%都记录在这篇文章里了. 1.ls命令 最常见的命令,相信刚进入linux命令行界面的时候,都要用这个命令看看当前目录下都有哪些文件吧. 名称:List 含义: ...

  2. Java中的equals和==的区别以及几个常用的object中的方法简单的调试方法

    一.equals 1.equals:是Object类中的方法,只能判断引用类型 2.默认判断的是地址是否相等(判断两个参数是否是同一个对象),子类中往往重写该方法,用于判断内容(值)是否相等 二.== ...

  3. 系统C盘空间严重的不足的几个清理方法

    大家在电脑使用久了以后,往往会遇到C盘空间不足的问题,这很可能进一步导致磁盘空间不足,软件无法正常运行,甚至电脑严重卡顿等问题. 下面给大家分享一些我自己在C盘空间不足过程中搜集的一些清理C盘空间的实 ...

  4. Solution -「USACO 2020.12 P」Spaceship

    \(\mathcal{Description}\)   Link.   Bessie 在一张含 \(n\) 个结点的有向图上遍历,站在某个结点上时,她必须按下自己手中 \(m\) 个按钮中处于激活状态 ...

  5. 我是如何破解你的WINDOWS密码的 ?(2)

    介绍 在这个系类的第一部分中,我们揭示了windows创建和储存密码的机制.我们也涉猎了一点两种加密方法的弱点和破解的方法.在这系列的第二篇也是最后一篇文章中,我会实战用网上免费的工具一步一步的来破解 ...

  6. Python基础—基础数据类型int、bool、str(Day3)

    一.int 数字 用于计算,+ - * / % **等 bit_lenth():转化成二进制的最小位数. i=4 print(i.bit_length())执行结果:3 1   0000 0001 2 ...

  7. spring boot全局配置文件优先级

    前两篇介绍的application配置文件,即为spring boot全局配置文件.那么spring boot加载配置文件的时候,怎么确定加载哪个目录下哪个文件呢? spring boot默认的配置文 ...

  8. jsp页面获取请求参数问题记录

    同一个请求可以从请求路径中获取参数,使用param.参数名 window.location.href = "admin/page.html?pageNum="+pageNum+&q ...

  9. requests post/get请求params参数和post请求正文的数据类型记录

    1. 前言 在写接口数据驱动测试框架时,(从excel表中读取的非数据的值都是str类型),发送post/get请求因为数据类型原因,请求失败,走了一些弯路,记录总结一下请求的参数或者请求正文的数据类 ...

  10. c++基础的记录(随笔记录一些基础的东西)

    1.父类的析构函数为什么要加上virtual关键字. 比如说,父类A,子类B.在A* a = new B()的语句的时候,如果父类析构函数没有virtual,我们在delete指针a的时候,会走父类的 ...