springcloud报错-------关于 hystrix 的异常 FallbackDefinitionException:fallback method wasn't found
典型如下
第一种
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;
}
}
- @HystrixCommand(fallbackMethod = "fallbackHi")
- public String getHi(String x) {
- String msg = restTemplate.getForObject("http://jack/hi", String.class);
- return msg;
- }
- public String fallbackHi(){
- return "can't say hi";
springcloud报错-------关于 hystrix 的异常 FallbackDefinitionException:fallback method wasn't found的更多相关文章
- SpringCloud报错:Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing MappingNode
今天在配置eureka集群时,SpringCloud报错如下: Caused by: org.yaml.snakeyaml.parser.ParserException: while parsing ...
- SpringCloud报错:Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
今天启动用eureka的服务消费者时,一直出现问题. SpringCloud报错: Caused by: org.springframework.context.ApplicationContextE ...
- 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 ...
- Xcode报错Expected selector for Objective-C and Expected method body
昨天把键盘拿起来拍一下清清灰,然后就发现Xcode报错了,Xcode报错Expected selector for Objective-C and Expected method body,也不知道什 ...
- springcloud报错集合
springcloud启动报错Connection refused: connect 参考:https://blog.csdn.net/deemo__/article/details/78932401 ...
- python中如何通过报错信息定位问题(异常传播轨迹)
class SelfException(Exception): pass def main(): firstMethod() def firstMethod(): secondMethod() def ...
- springcloud报错:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'armeriaServer' defined in class path resource
spring boot配置zipkin 无法启动 加入 Zipkin Server 由于需要收集 Spring Cloud 系统的跟踪信息,以便及时地发现系统中出现的延迟升高问题并找出系统性能瓶颈的根 ...
- Springcloud报错:java.lang.IllegalStateException: Service id not legal hostname (/a-service)
今天在做springcloud链路追踪的时候,报错java.lang.IllegalStateException: Service id not legal hostname (/a-service) ...
- SpringCloud报错:com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
启动SpringCloudEureka 报错:com.netflix.discovery.shared.transport.TransportException: Cannot execute req ...
随机推荐
- rtsp监控直播转码用到EasyNVR
第一 下载EasyNVR_win_v2.6.18.0320 第二 安装启动 第三 配置转码路径 http://localhost:10800/ 最后转码播放 /hls/stream_1/stream_ ...
- 【C++】近期C++特性进阶学习总结(一)
前言 C++的特性多的数不胜数,语言标准也很多,所以不定期对近期所学的C++知识进行总结,是对自身知识体系检查的良好机会,顺便锻炼一下写博客的文笔 三/五/零之法则 三之法则:如果某个类需要用户定义的 ...
- Vue.use初探
Vue.use 问题 相信很多人在用Vue使用别人的组件时,会用到 Vue.use(). 例如:Vue.use(VueRouter).Vue.use(MintUI). 但是用 axios时,就不需要用 ...
- 《PHP程序员面试笔试宝典》——什么是职场暗语?
本文摘自<PHP程序员面试笔试宝典> 文末有该书电子版下载. 随着求职大势的变迁发展,以往常规的面试套路因为过于单调.简明,已经被众多"面试达人"们挖掘出了各种&quo ...
- 羽夏闲谈—— C 语言入门之问
前言 最近加入了一个QQ频道,有很多想学C的纯小白.为什么这么说呢?因为他们会问一些环境用啥?为啥我配置不行?看了教程配置环境我也不会,咋配置?为啥这里代码这里有错误?啥语言好不好?诸如此类的问题 ...
- 扫盲贴:2021 CSS 最冷门特性都是些啥?
最近几年 CSS 界的大事之一是每年年底的 <State Of CSS>,也就是 CSS 现状调查,去年年底发布了<State Of CSS 2021>.其中关于特性这一章,会 ...
- Renix中如何实现流调速——网络测试仪实操
在Renix操作中有时我们需要进行流调速,那么如何实现呢?接下来为您详细介绍. 第一步:预约测试资源 首先打开Renix软件,连接机箱, 预约端口 第二步:流调速 例如:端口下有3条流,分别设置为10 ...
- IP网络性能测试工具——Renix Perf
一.Renix Perf 基于软件的网络及应用服务性能测试工具 · 双臂测试 · 单臂测试 通过测试端点产生网络流量对网络性能进行测量 · TCP.UDP.PING · 语音.视频.HTTP.FTP. ...
- 实例演示:Excel实现数据更新获取,并根据公式计算后展示
我们数据库中有一些明细数据,希望我们可以使用Excel的公式,对报表数据进行,最后展示在自定义的行列固定报表中. 如下图:从左侧表中获取大类名称为饮料.海鲜.日用品,从2016/11/11到201 ...
- textbox 实现跨操作系统换行的两种写法
每个操作系统对换坏的解释都不一样.所以写代码的时候要注意这个细节: 要基于.net跨环境的基类去写,才能跨平台. Unix系统里,每行结尾只有"<换行>",即" ...