Springcloud RestTemplate服務調(diào)用代碼實例
更新時間:2020年08月19日 15:53:30 作者:陶海軍
這篇文章主要介紹了Springcloud RestTemplate服務調(diào)用代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
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方式調(diào)用沒有經(jīng)過服務注冊中心獲取服務地址,代碼寫死不利于維護,當服務宕機時不能高效剔除。
2.調(diào)用服務時沒有負載均衡需要自己實現(xiàn)負載均衡策略。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
mybatis如何實現(xiàn)in傳入數(shù)組查詢
這篇文章主要介紹了mybatis如何實現(xiàn)in傳入數(shù)組查詢方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10SpringBoot設置靜態(tài)資源訪問控制和封裝集成方案
這篇文章主要介紹了SpringBoot靜態(tài)資源訪問控制和封裝集成方案,關于springboot靜態(tài)資源訪問的問題,小編是通過自定義webconfig實現(xiàn)WebMvcConfigurer,重寫addResourceHandlers方法,具體完整代碼跟隨小編一起看看吧2021-08-08java為什么使用BlockingQueue解決競態(tài)條件問題面試精講
這篇文章主要為大家介紹了java為什么使用BlockingQueue解決競態(tài)條件問題面試精講,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10