1.服務productservices
1
2
3
4
5
6
7
8
9
10
|
@RestController public class ProductController { @RequestMapping ( "/product/findAll" ) public Map findAll(){ Map map = new HashMap(); map.put( "111" , "蘋果手機" ); map.put( "222" , "蘋果筆記本" ); return map; } } |
2.服務userservices
1
2
3
4
5
6
7
8
9
10
|
@RestController public class UserController { @RequestMapping ( "/user/showProductMsg" ) public String showProductMsg(){ String msg = restTemplate.getForObject( "http://127.0.0.1:9001/product/findAll" ,String. class ); return msg; } } |
3.問題
1.直接使用restTemplate方式調(diào)用沒有經(jīng)過服務注冊中心獲取服務地址,代碼寫死不利于維護,當服務宕機時不能高效剔除。
2.調(diào)用服務時沒有負載均衡需要自己實現(xiàn)負載均衡策略。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://www.cnblogs.com/taohaijun/p/13457335.html