feign配置

1,引入feign依赖


            org.springframework.cloud
            spring-cloud-starter-openfeign
        

2,配置feign

@FeignClient(value = "service-cat", fallbackFactory = 
CatServiceFeignClientFallbackFactory.class)
@Qualifier("catServiceFeignClient")
public interface CatServiceFeignClient {

    @GetMapping("/cat/test/{value}")
    String test(@PathVariable("value") String value);
}

配置fallbackfactory

@Slf4j
@Component
public class CatServiceFeignClientFallbackFactory implements FallbackFactory {
    @Override
    public CatServiceFeignClient create(Throwable throwable) {
        return new CatServiceFeignClient() {
            @Override
            public String test(String value) {
                log.error("测试,参数=>【{}】", value);
                return null;
            }
        };
    }
}

你可能感兴趣的:(微服务)