文章目录
一、Feign实现远程调用
1.替换RestTemplate发起远程调用,RestTemplate存在的问题:
代码可读性差,编程体验不统一。
参数复杂URL难以维护。
2.实现Feign远程调用:
在order-service的pom.xml配置文件中引入依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
在order-service的启动类添加@EnableFeignClients
注解。
在clients层中编写Feign客户端:
@FeignClient("userservice")
public interface UserClient {
@GetMapping("/user/{id}")
User findById(@PathVariable("id") Long<