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