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 ...
随机推荐
- iOS 性能优化系列
Objective-C 高性能的循环 使用 Swift 和 Objective-C 执行 iOS 内存管理的 7 个简单技巧 @autoreleasepool-内存的分配与释放
- 通过 call/cc 给 Ice 实现 Coroutine
前两天给 Ice 加了 call/cc, 为此还重构了一波, 实现 call/cc 还是因为看了轮子哥的大专系列( 里边说提供 continuation 语言实现 Coroutine 起来很轻松, 后 ...
- Java线程的实现/创建方式
1.继承Thread类: Thread 类本质上是实现了 Runnable 接口的一个实例,代表一个线程的实例. 启动线程的唯一方法就是通过 Thread 类的 start()实例方法. start( ...
- Spring Cloud之服务注册中心搭建Eureka Server服务注册中⼼
Spring Cloud并不与Spring MVC类似是一个开源框架,而是一组解决问题的规范(个人理解).解决哪些问题呢?如下: 1)服务管理:⾃动注册与发现.状态监管 2)服务负载均衡 3)熔断 4 ...
- corn定时任务
(1) Seconds Minutes Hours DayofMonth Month DayofWeek Year (2)Seconds Minutes Hours DayofMonth Month ...
- 如何深入学习Java并发编程?
在讲解深入学习Java并发编程的方法之前,先分析如下若干错误的观点和学习方法. 错误观点1:学习Java编程主要是学习多线程. 这话其实是说明了表面现象,多线程其实还真是并发编程的实现方式,但在实际高 ...
- 【第一期百题计划进行中,快来打卡学习】吃透java、细化到知识点的练习题及笔试题,助你轻松搞定java
[快来免费打卡学习]参与方式 本期百题计划开始时间:2022-02-09,今日打卡题已在文中标红. 0.本文文末评论区打卡,需要登录才可以打卡以及查看其他人的打卡记录 1.以下练习题,请用对应的知识点 ...
- 开发Windows程序的三种方式
软件开发方式一共有三种:SDK方式.MFC开发方式.托管环境的开发都是基于消息的开发 SDK方式 原装api的调用SDK方式使用C语言和Windows应用程序编程接口(Windows API)来开发W ...
- vs2019 NuGet安装及简单使用
Nuget介绍 官网定义:NuGet是.NET的软件包管理器(免费).NuGet客户端工具提供了生成和使用软件包的能力.NuGet Gallery 是所有软件包作者和消费者都使用的中央软件包存储库. ...
- dbeaver安装配置
安装出现库依赖没有,可以添加maven仓库 修改字体:小四