1.服務productservices
@RestController
public class ProductController {
@RequestMapping("/product/findAll")
public Map findAll(){
Map map = new HashMap();
map.put("111","蘋果手機");
map.put("222","蘋果筆記本");
return map;
}
}
2.服務userservices
@RestController
public class UserController {
@RequestMapping("/user/showProductMsg")
public String showProductMsg(){
RestTemplate restTemplate = new RestTemplate();
String msg = restTemplate.getForObject("http://127.0.0.1:9001/product/findAll",String.class);
return msg;
}
}
3.問題
1.直接使用restTemplate方式調用沒有經過服務注冊中心獲取服務地址,代碼寫死不利於維護,當服務宕機時不能高效剔除。
2.調用服務時沒有負載均衡需要自己實現負載均衡策略。
