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

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


    org.springframework.cloud
    spring-cloud-starter-feign
    1.4.2.RELEASE

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 "服务降级";
        }
    }
}

你可能感兴趣的:(springcloud,java)