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