问题描述
在开发spring-cloud项目的时候,Feign的熔断器不起作用,指定了fallback不起作用。
@FeignClient(name="produce", fallback=ProduceCallback.class)publicinterfaceProduceSevice{@RequestMapping("/index")Stringindex();}
@ComponentpublicclassProduceCallbackimplementsProduceSevice{@OverridepublicStringindex(){return"this is error";}}
当produce停掉以后,直接报错,不会走fallback指定的熔断方法。
互联网上的解决方案
基本上网络上都是指的没有开启hystrix,解决方法是在yml中设置
feign:hystrix:enabled:true
但是按照这个办法,不起作用 。
摸索到的解决方法
下载了很多源代码,在我本地跑起来hystrix可以起作用,但是我自己建立的项目就是无法起作用。类似的貌似还有bootstrap.yml不起作用。最后排除发现和网络上的代码最大的产品就是spring-cloud的版本区别。
<properties> <java.version>1.8</java.version> <spring-cloud.version>2020.0.0-M6</spring-cloud.version> </properties>
我用IDEA建立项目后默认的spring-cloud.version版本是这个样子的。
官网关于spring-cloud.version的介绍
我修改为 Hoxton.SR9 后一切正常。同时把springboot的版本降低为2.3.5.REALSE后表现正常,莫非2020.0.0-M6后对这块代码有巨大变化。