典型如下

第一种

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. 给 zsh 自定义命令添加参数自动补全

    有时我会自定义一些 zsh 命令,以便提升某些高频操作的效率.本文记录我给一个自定义命令添加参数自动补全的方法. 场景 我自定义了一个 zsh 命令 gmt,执行 gmt <b2>,可以将 ...

  2. 【BZOJ5492】校园旅行(图论 搜索优化)

    题目链接 大意 给出\(N\)个点,\(M\)条边的一张图,其中每个点都有一个0或1的颜色. 再给出\(Q\)个询问,每次询问查询两个点之间是否存在一条路径,使得路径上的颜色组成的01字符串是一个回文 ...

  3. 用Java实现在123456789中随机插入+或者-,使表达式的结果为100

    这里我的思路是暴力算法.就是不断试错,不限循环次数,直到找到正确的情况为止. 通过走随机,不断控制在123456789中添加+或者-,再通过正则表达式筛选出所有的数字(包含正负),转换为Integer ...

  4. Linux运行级别及解释

    Linux中有七个运行级别,分别为0~7 0级:关机 1级:单用户(找回丢失密码) 2级:多用户无网络 3级:多用户有网络,最常用的级别 4级:保留,目前Linux暂无使用 5级:图像界面 6级:重启 ...

  5. linxu 查看运行日志

    journalctl - 检索 systemd 日志 journalctl 可用于检索 systemd(1) 日志(由 systemd-journald.service(8) 记录). 如果不带任何参 ...

  6. HMS Core机器学习服务助力Zaful用户便捷购物

    Zaful是近年来发展良好的出海电商平台,主打快时尚.在洞察其用户有购买街头海报.生活中同款衣物的需求后,Zaful联合HMS Core机器学习服务打造拍照购物服务.用户拍照后可在预设的商品图片库中搜 ...

  7. Solution -「NOI.AC 省选膜你赛」union

    题目 题意简述   给定两颗树 \(A,B\),\(A\) 中的任一结点 \(u\) 与 \(B\) 中的任一结点 \(v\) 都有一个关系值 \(f(u,v)\),初始为 \(0\).再给出 \(q ...

  8. 对象到底是怎么new出来的

    前言:要想理解本文,必须先了解JVM的内存结构 一.创建对象的方式 new:最常见 反射:Class.newInstance() 使用clone() 反序列化 二.创建对象的步骤(对象在JVM中怎么存 ...

  9. 【性能测试实战:jmeter+k8s+微服务+skywalking+efk】系列之:性能监控、分析、调优等

    说明: 本文是基于虚拟机演示的,资源有限 skywalking中拓扑图 kubectl get po -A -owide 测试执行:单场景 查询礼品 jmeter -n -t gift.jmx -l ...

  10. 【C# .Net GC】手动监视和控制对象的生命周期(GCHandle)

    这个话题还未做详细研究,暂时用不到,只是粗略看了一下. 使用System.Runtime.InteropServices.GCHandle类来手动控制对象的生命周期 (个人感觉这里可能有一些问题... ...