Eureka:Client的相互通讯的方式
两个注册在Eureka的client怎么实现通讯的呢?
前提:注册2调用注册1的api
第一种:直接调用url
借助: RestTemplate 类
package com.example.demouseapi.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class usecontroller {
@RequestMapping("usesayhello")
@ResponseBody
public String usesayhello(){
//直接调用接口
RestTemplate template=new RestTemplate();
String s= template.getForObject("http://localhost:8081/UserSay",String.class);
return s;
}
}