2.4 Http客户端Feign
RestTemplate方式调用存在的问题
- 代码可读性差,编程体验不统一
- 参数复杂URL难以维护
String url="http://userservice/user/"+order.getUserId();
User user = restTemplate.getForObject(url, User.class);
2.4.1 定义及使用Feign客户端
①引入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
②主启动类上加上@EnableFeignClients注解开启Feign的功能
@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
@EnableFeignClients
public class OrderApplicatio