- 添加依赖:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency>
- 主启动类添加: @EnableCircuitBreaker
- 简单使用:
/** * @author sw * @data 2021/8/10 8:06 */ @RequestMapping("/customer") @RestController public class CustomerController { @Resource private ProviderService providerService; /** * @HystrixCommand fallBack为兜底方法 */ @HystrixCommand(fallbackMethod = "fallBack", commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "3000") }) @GetMapping("/list") public List<User> all() { return providerService.all(); } public List<User> fallBack() { List<User> list = new ArrayList<>(); User user = new User(); user.setName("测试"); list.add(user); return list; } }
12-05
436
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-18
3007
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-29
1062
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)