SpringCloud Finchley.SR1版本 在feign 上使用 hystrix
一.Feign client 中加入hystrix的 fallaback。
@FeignClient(value = “usercenter-client”,fallback = UserCenteriServiceHystric.class)
public interface UserCenterService {
@GetMapping(“hello”)
String consumer();
}
二 编写 UserCenterServiceHystric.Class
@Component
public class UserCenteriServiceHystric implements UserCenterService {
@Override
public String consumer() {
return “sorry 请求用户中心信息异常”;
}
}
三.启动类中添加注解
@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
@EnableAutoConfiguration
@EnableCircuitBreaker
public class OrangeMarketApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(OrangeMarketApplication.class).web(true).run();
}
}