maven引入
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
启动类加
@EnableFeignClients(clients = {OrderPayFeignClient.class})
OrderPayFeignClient是调用封装类
@Component
@FeignClient(name = "SHOP-SERVICE", fallback = ProtaoOrderFeignFallback.class)
public interface ProtaoOrderFeign {
@RequestMapping(value = "/memberOrder/getOrderInvoceInfo", method = RequestMethod.POST)
CommonResult<OrderInvoceDto> getOrderInvoceInfo(@RequestParam("orderId") Long orderId);
}
失败处理类
@Component
@Slf4j
public class ProtaoOrderFeignFallback implements ProtaoOrderFeign {
@Override
public CommonResult getOrderInvoceInfo(Long orderId) {
log.info("该订单调用查询订单发票信息失败,订单号:{}", orderId);
return CommonResult.failed("调用查询发票信息失败");
}
}