springCloud-4.RestTemplat的使用(两个client之间的调用)

1.启动eurka-server

294a77befbd3ce06dafdda266c5d4ae2739.jpg

2.在client端口8080编写一个hello world方法,并且能访问

96694dcefbb3339a0df4b457df0e3a53dc0.jpg

56e07fced13c2b94a38fdad697c1fe3f68d.jpg

90b92307cefb87545d3cff2a8fc94b316df.jpg

 

3.创建client-test1项目

336f5e58349f7eee5872e1e8730a089fbc1.jpg

4.调用EUREKA-CLIENT的index方法,新建RestTemplat启动配置

6805c21ce000965c205eb63fa6bb8702c0d.jpg

5.新建调用index类

package com.client.test.clienttest1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * 描述:
 *
 * @outhor hekang
 * @create 2018-07-30 下午3:31
 */
@RestController
public class ClientController {
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("getIndex")
    public String getIndex(){
        String res = restTemplate.getForObject("http://EUREKA-CLIENT/index", String.class);
        return  res;
    }

}

 

6.启动,访问http://localhost:8081/getIndex,测试

注册成功:

9ce636ef6a74f1388935cc3a68fc3164f9a.jpg

 

访问http://localhost:8081/getIndex   成功打印

f6b2802515c8afe6ec901f0770209c0760f.jpg

 

 

转载于:https://my.oschina.net/u/1046143/blog/1919724

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值