关于在Spring Cloud Feign工程中使用Hystrix配置不生效的问题
来源:互联网 发布:java流程控制语句 编辑:程序博客网 时间:2024/06/05 17:24
feign.hystrix.enabled=true而且需要添加hystrix的依赖,如果你是通过idea中的spring initializr 创建的spring cloud项目,你可以在pom文件中再添加:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId></dependency>
在Dalston版本中,要开启Feign对Hystrix的支持,这两个条件缺一不可,这些可以在spring cloud官方文档中找到说明。书上用的是Brixton版本,如果你按照书上的做可能不会成功,不同版本的spring cloud差异还是很大的。
如果你按照上面的要求做了,还是不生效,原因是这样的:如果你从看这本书起,一直按照书上的案例来做,比如这一部分书上建的新项目是feign-consumer,当你按照书上讲的内容的顺序来做测试的话,比如看到第211页“禁用Hystrix”这一部分,你可能也新建了一个类:
@Configurationpublic class DisableHystrixConfiguration { @Bean @Scope("prototype") public Feign.Builder feignBuilder(){ return Feign.builder(); }}
这个类是通过使用@Scope("prototype")注解为指定的客户端配置Feign.Builder实例,从而构建一个关闭Hytrix的配置类,接下来书中就说让你在HelloService的@FeignClient注解中,通过configuration参数引入上面实现的配置:
@FeignClient(name = "hello-service", configuration = DisableHystrixConfiguration.class)public interface HelloService { @RequestMapping("/hello") String hello(); @GetMapping(value = "/hello1") String hello(@RequestParam("name") String name); @GetMapping(value = "/hello2") User hello(@RequestHeader("name") String name, @RequestHeader("id") int id); @PostMapping(value = "/hello3") String hello(@RequestBody User user);}
这样确实是实现禁用了,后来你又想测试服务降级配置,你又想开启对Hystrix的支持,然后想把@FeignClient注解中的configuration参数去掉就行了吧,例如:
@FeignClient(name = "hello-service", fallback = HelloServiceFallback.class)//,configuration = DisableHystrixConfiguration.class)运行后你按照第214页所讲的:先启动服务注册中心和feign-consumer,但是不启动hello-service服务。发送GET请求到http://localhost:9001/feign-consumer2,你会发现服务降级并没有生效,而且还报错了:com.netflix.client.ClientException: Load balancer does not have available server for client: hello-service
原因就是写的那个个配置类DisableHystrixConfiguration上面还有@Configuration注解:
@Configurationpublic class DisableHystrixConfiguration {就算你在@FeignClient注解中没有引用该配置类,他也会被启动类上的注解扫描到(参见@SpringBootApplication注解中的@ComponentScan注解),所以跟着书上案例调试服务降级的时候记得把DisableHystrixConfiguration这个类全部注掉,然后满足那两个条件就OK了
Dalston版本官网发布笔记关于Feign对Hystrix支持部分:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign-hystrix
还有为什么Feign对Hystrix的支持默认是关闭状态的原因讨论:https://github.com/spring-cloud/spring-cloud-netflix/issues/1277
- 关于在Spring Cloud Feign工程中使用Hystrix配置不生效的问题
- 关于在Spring Cloud Feign工程中使用Ribbon配置不生效的问题
- Spring Cloud 的 Hystrix 在 Feign上使用 Hystrix功能
- 关于Dalston.SR3版本的spring cloud,用feign客户端调用服务hystrix不能生效的问题
- spring cloud,用feign客户端调用服务hystrix不能生效的问题
- spring cloud-Feign的Hystrix支持
- Spring Cloud 的 Hystrix 为Feign禁用Hystrix
- spring cloud-Feign使用中遇到的问题总结
- Spring cloud系列十一 @Feign集成的Hystrix进行个性化配置及集成原理
- 在dropwizard中使用feign,使用hystrix
- Spring Cloud Netflix 教程(Feign+Ribbon+Hystrix)
- spring cloud feign hystrix doesn't work
- Spring Cloud中Feign配置详解
- Spring Cloud中如何优雅的使用Feign调用接口
- spring cloud 使用feign 遇到问题
- Spring Cloud feign使用
- Spring Cloud 的 Feign 组件 自定义配置
- 微服务框架Spring Cloud: 在微服务系统中使用Hystrix, Hystrix Dashboard与Turbine
- 字典序排序n!
- HDU 1686 Oulipo KMP入门
- eclipse 与资源库同步时忽略多余文件的一种方法
- spring工作原理以及同原始java执行的对比
- 0元购 斐讯K2路由器免费拿 399返现399
- 关于在Spring Cloud Feign工程中使用Hystrix配置不生效的问题
- 100. Same Tree(Java)
- vue 饿了么模拟后台数据
- Java奇淫巧技之Lombok
- 教你做炫酷的碎片式图片切换 (canvas)
- 线程中wait、notify、notifyAll的使用方法
- 从RDD的角度来看Spark内部原理
- VS调试js学习总结
- 对html与body的一些研究与理解