一、为指定的Feign客户端禁用Hystrix
1) 创建一个Feign禁用Hystrix的禁用配置类
package com.itmuch.cloud;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import feign.Feign;
/**
* 为Feign禁用Hystrix功能
* @author tobin
*
*/
@Configuration
public class FeignDisableHystrixConfiguration {
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
return Feign.builder();
}
}
2) Feign接口类的配置
package com.itmuch.cloud;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(name="cloud-service", configuration = FeignDisableHystrixConfiguration.class) // 服务端提供者的name
public interface UserFeignClient {
@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
public User findById(@PathVariable("id") Long id);
}
二、全局禁用Hystrix
只需要在yml文件中配置, feign.hystrix.enabled = false 即可.