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

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();

    @Component
    static class ProductClientFallback implements ProductClient{

        @Override
        public String productMsg() {
            return "服务降级";
        }
    }
}

版权声明:本文为qq_38522268原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。