微服务之间的远程调用
基于RestTemplate发起的HTTP请求实现远程调用
HTTP请求做远程调用是与语言无关的调用,只需要知道对方的ip、端口、接口路径、请求参数即可。
没有进行调用之前是无法进行对用户数据的查询的
远程调用步骤大概分为:
注册RestTemplate
package cn.itcast.order;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
public class OrderApplication {
public static void main(String[] args) {
SpringApplication.run(OrderApplication.class, args);
}
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
2…实现远程调用
从而实现最终的结果