一、指定统一的降级方法
/**
* 指定统一的降级方法
* * 参数 : 没有参数
*/
public Product defaultFallBack() {
Product product = new Product();
product.setProductName("触发统一的降级方法");
return product;
}
二、不需要在需要降级的方法上面添加:@HystrixCommand(fallbackMethod = “orderFallBack”),在类上面配置统一的降级方法:@DefaultProperties(defaultFallback = “defaultFallBack”)
@RestController
@RequestMapping("/order")
/**
* @DefaultProperties : 指定此接口中公共的熔断设置
* 如果过在@DefaultProperties指定了公共的降级方法
* 在@HystrixCommand不需要单独指定了
*/
@DefaultProperties(defaultFallback = "defaultFallBack")
public class OrderController {
@Autowired
private RestTemplate restTemplate;
/**
* 指定统一的降级方法
* * 参数 : 没有参数
*/
public Product defaultFallBack() {
Product product = new Product();
product.setProductName("触发统一的降级方法");
return product;
}
注意:
当使用统一的降级方法的时候,需要规定所有的接口返回同一种数据类型,这样在定义统一的降级方法的时候才能够定义返回类型。