@FeignClient 对接口进行服务降级方法的实现,调用不起作用的原因【feign】
·
我搜了一下 加了一个配置 就完事了
feign:
#hystrix:
#enabled: true过时了 springcloud2020.0.1改为以下了
circuitbreaker:
enabled: true #feign作为客户端使用hystrix必须开启,服务端没有feign所以没有这个.
已经没有前者注解了。现在改为circuitbreaker了
修改之后接口实现类就可以被成功调用,完美。


@FeignClient(value = "SentinelServer",configuration = LoadBalancePolicy.class,fallback = OrderServiceFallBackImpl.class)
public interface RemoteOrderService {
@GetMapping("/order/queryOrderById")
public Result queryOrderById(@RequestParam("id") int id);
}
@Service
public class OrderServiceFallBackImpl implements RemoteOrderService {
@Override
public Result queryOrderById(@RequestParam("id") int id) {
return new Result(ResultStatus.ERROR.getReturncode(),"远程服务器异常,无法连接","");
}
}
更多推荐
所有评论(0)