美文网首页
微服务之间相互调用

微服务之间相互调用

作者: MaJiT | 来源:发表于2020-07-18 17:23 被阅读0次

1. 启动中加入RestTemplate

@Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

2.控制层中调用RestTemplate中的各种方法

//通过pid获取另一个服务中的Product对象 
Product product =restTemplate.getForObject("http://localhost:8081/product/" + pid, Product.class);

相关文章

网友评论

      本文标题:微服务之间相互调用

      本文链接:https://www.haomeiwen.com/subject/yljfkktx.html