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 ...
随机推荐
- push自定义动画
// // ViewController.m // ViewControllerAnimation // // Created by mac on 15/5/26. // Copyright ...
- 取代 Mybatis Generator,这款代码生成神器配置更简单,开发效率更高!
作为一名 Java 后端开发,日常工作中免不了要生成数据库表对应的持久化对象 PO,操作数据库的接口 DAO,以及 CRUD 的 XML,也就是 mapper. Mybatis Generator 是 ...
- 20161206日更新CocoaPods版本
从网上下载的工程第三方库需要更新,但当我执行pod update时提示以下错误: [!] The `master` repo requires CocoaPods 1.0.0 - (currentl ...
- 如何通过opensea-js获取OpenSea的数据
OpenSea作为NFT最大的交易平台,随着NFT的火热之后,热度也是出现翻天覆地的变化.作为开发人员肯定好奇有没有可以与opensea交互的包来开发相关的工具或者快速获取opensea的数据.别急, ...
- Solution -「Gym 102956A」Belarusian State University
\(\mathcal{Description}\) Link. 给定两个不超过 \(2^n-1\) 次的多项式 \(A,B\),对于第 \(i\in[0,n)\) 个二进制位,定义任意一个二元 ...
- v77.01 鸿蒙内核源码分析(消息封装篇) | 剖析LiteIpc(上)进程通讯内容 | 新的一年祝大家生龙活虎 虎虎生威
百篇博客分析|本篇为:(消息封装篇) | 剖析LiteIpc进程通讯内容 进程通讯相关篇为: v26.08 鸿蒙内核源码分析(自旋锁) | 当立贞节牌坊的好同志 v27.05 鸿蒙内核源码分析(互斥锁 ...
- Spring Boot自动配置实战
上篇讲述了Spring Boot自动配置的原理,本篇内容就是关于该核心原理的实际应用.需求即当某个类存在的时候,自动配置这个类的bean并且这个bean的属性可以通过application.prope ...
- 拜托,使用Three.js让二维图片具有3D效果超酷的好吗 💥
声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 逛 sketchfab 网站的时候我看到有很多二维平面转 3D 的模型例子 ...
- Kubernetes集群使用CentOS 7.6系统时kubelet日志含有“Reason:KubeletNotReady Message:PLEG is not healthy:”信息
问题描述 Kubernetes集群使用CentOS 7.6版本的系统时,kubelet日志中可能存在以下告警信息. Reason:KubeletNotReady Message:PLEG is not ...
- Python中模块、类、函数、实例调用案例
19 a = '我是模块中的变量a' 20 21 def hi(): 22 a = '我是函数里的变量a' 23 print('函数"hi"已经运行!') 24 25 class ...