一、为指定的Feign客户端禁用Hystrix 1) 创建一个Feign禁用Hystrix的禁用配置类
代码语言:javascript复制import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import feign.Feign;
/**
* 为Feign禁用Hystrix功能
*/
@Configuration
public class FeignDisableHystrixConfiguration {
@Bean
@Scope("prototype")
public Feign.Builder feignBuilder() {
return Feign.builder();
}
}
2) Feign接口类的配置
代码语言:javascript复制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,这样cloud-service这个服务将不会受到hystrix保护
public interface UserFeignClient {
@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
public User findById(@PathVariable("id") Long id);
}
二、全局禁用Hystrix 只需要在yml文件中配置, feign.hystrix.enabled = false 即可.