上一篇文章中我们实现了通过RestTemplate进行远程调用的方法,那么实际上我们还可以使用openfeign进行远程调用
首先在订单服务中引入openfeign依赖

接着在启动类中添加 @EnableFeignClients 注解

接着编写openfeign客户端
java
@FeignClient(value = "service-product")
public interface ProductFeignClient {
@GetMapping("/getProduct/{id}")
Product getProductById(@PathVariable("id") Long productId);
}
在service中进行注入并且调用

由于我们在openfeign客户端中的返回类型是Product,因此需要修改service-product中controller的返回类型

最后在浏览器中调用接口就可以得到数据
