Fegin:伪RPC客户端(本质还是用http)
使用fegin,和ribbon一样,也是发送请求
一:添加fegin依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
启动类添加注解@@EnableFeignClients
@SpringBootApplication
@EnableFeignClients
public class OrderServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication.class, args);
}
}
二:编写调用接口
这里就相当于这句话
Map<String,Object> productMap = restTemplate.getForObject("http://product-service//api/v1/product/find?id="+productId, Map.class);
/**
* 商品服务客户端
*/
@FeignClient(na