典型如下

第一种

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. OSPF多区域的进阶强化版

    OSPF多区域 1.OSPF多区域原理 2.末梢区域配置 1.生成OSPF多区域的的原因:改善网络的可扩展性,快速收敛. OSPF的三种通信量:a域内通信量(单个区域内的路由器之间交换数据包构成的通信 ...

  2. 抽象类,interface接口,接口和继承的区别

    一.抽象类 需要抽象类的原因:父类方法不确定性的问题.考虑将该方法设计为抽象(abstract)方法所谓抽象方法就是没有实现的方法.所谓没有实现就是指,没有方法体.当一个类中存在抽象方法时,需要将该类 ...

  3. python文件操作方式

    一.文件操作 1.什么是文件 文件是操作系统暴露给用户能够快捷方便操作硬盘的快捷方式(接口) 2.代码如何操作文件 关键字:open() 三步走: 1.利用关键字open打开文件 2.利用其他方法操作 ...

  4. 【Elastic-1】ELK基本概念、环境搭建、快速开始文档

    TODO 快速开始文档 SpringBoot整合ELK(Logstash收集日志.应用主动向ES写入) ELK接入Kafka 基本概念 ElasticSearch 什么是ElasticSearch? ...

  5. 你所不知道的 C# 10新特性

    我们很高兴地宣布 C# 10 作为 .NET 6 和 Visual Studio 2022 的一部分已经发布了.在这篇文章中,我们将介绍 C# 10 的许多新功能,这些功能使您的代码更漂亮.更具表现力 ...

  6. [源码解析] NVIDIA HugeCTR,GPU 版本参数服务器---(7) ---Distributed Hash之前向传播

    [源码解析] NVIDIA HugeCTR,GPU 版本参数服务器---(7) ---Distributed Hash之前向传播 目录 [源码解析] NVIDIA HugeCTR,GPU 版本参数服务 ...

  7. C#异步编程由浅入深(三)细说Awaiter

      上一篇末尾提到了Awaiter这个类型,上一篇说了,能await的对象,必须包含GetAwaiter()方法,不清楚的朋友可以看上篇文章.那么,Awaiter到底有什么特别之处呢?   首先,从上 ...

  8. [题解]第十一届北航程序设计竞赛预赛——H.高中数学题

    题目描述 解题思路 可以求得通项公式:an = 2n + 1,所以问题就变成等差数列求异或和,这个具体为什么对我还不能很好地解释清楚,先挖坑吧. 附:c++代码 1 #include <iost ...

  9. containerd与kubernetes集成部署

    概念介绍 cri (Container runtime interface) cri is a containerd plugin implementation of Kubernetes conta ...

  10. 【C# Parallel】开端

    使用条件 1.必须熟练掌握锁.死锁.task的知识,他是建立这两个的基础上的.task建立在线程和线程池上的. 2.并不是所有代码都适合并行化. 例如,如果某个循环在每次迭代时只执行少量工作,或它在很 ...