springCloud-4.RestTemplat的使用(兩個client之間的調用)

1.啓動eurka-serverjava

2.在client端口8080編寫一個hello world方法,而且能訪問web

 

3.建立client-test1項目spring

4.調用EUREKA-CLIENT的index方法,新建RestTemplat啓動配置app

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,測試3d

註冊成功:rest

 

訪問http://localhost:8081/getIndex   成功打印code

相關文章
相關標籤/搜索