1.启动eurka-server
2.在client端口8080编写一个hello world方法,并且能访问
3.创建client-test1项目
4.调用EUREKA-CLIENT的index方法,新建RestTemplat启动配置
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 */@RestControllerpublic 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,测试
注册成功:
访问http://localhost:8081/getIndex 成功打印