当服务出现错误的时候(可能是返回状态, 也可能是服务down掉了), fallback 并没有触发.
并不需要在 application.yml 配置
feign:
hystrix:
enabled: true
而是应该配置:
feign:
circuitbreaker:
enabled: true
Application.java
中需要添加注解 @EnableHystrix
, 可以看到 EnableHystrix
继承了 EnableCircuitBreaker
.
在包 spring-cloud-openfeign-core-3.0.1.jar
中查看配置, 并没有找到 hystrix 相关的配置, 但是有一个配置是:
{
"name": "feign.circuitbreaker.enabled",
"type": "java.lang.Boolean",
"description": "If true, an OpenFeign client will be wrapped with a Spring Cloud CircuitBreaker circuit breaker.",
"defaultValue": "false"
}
注意 我这是依赖的包:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.7.RELEASE</version>
</dependency>