当前位置: 代码迷 >> 综合 >> springcloud 的feign使用hystrix,实现服务降级
  详细解决方案

springcloud 的feign使用hystrix,实现服务降级

热度:60   发布时间:2023-12-22 15:31:22.0

feign的server和client都要引入feign依赖

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-feign</artifactId><version>1.4.2.RELEASE</version>
</dependency>

feign的client配置application.yml

feign:hystrix:enabled: true

feign的client的启动类添加扫描路径注解

@ComponentScan(basePackages="com.example")

feign的server配置fallback

@FeignClient(name="product",fallback =ProductClient.ProductClientFallback.class )
@Component
public interface ProductClient {@GetMapping("/msg")String productMsg();@Componentstatic class ProductClientFallback implements ProductClient{@Overridepublic String productMsg() {return "服务降级";}}
}
  相关解决方案