一、实现步骤
- 在配置文件application.yml中开启feign熔断器支持
- 编写FallBack处理类,实现FeignClient客户端
- 在@FeignClient注解中,指定FallBack处理类。
- 测试
1. 在配置文件application.yml中开启feign熔断器支持:默认关闭

# 开启Feign的熔断功能
feign:
hystrix:
enabled: true
2. 编写FallBack处理类,实现FeignClient客户端
package com.william.service.Impl;
import com.william.domain.User;
import com.william.service.UserClient;
import org.springframework.stereotype.Component;
/**
* @author :lijunxuan
* @date :Created in 2019/6/30 19:40
* @description :
* @version: 1.0
*/
@Component //把实现类注入到Spring 容器中
public class UserClientFallBack implements UserClient {
@Override
public User findById(Integer id) {
User user = new User();
user.setId(id);
user.setName("用户异常");
return user;
}
}
3. 在@FeignClient注解中,指定FallBack处理类。

4. 测试
(1)把提供者给停止运行

(2)地址栏输入http://localhost:8080/findByIdFeign?id=1
