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