Springcloud RestTemplate服務(wù)調(diào)用代碼實(shí)例
1.服務(wù)productservices
@RestController public class ProductController { @RequestMapping("/product/findAll") public Map findAll(){ Map map = new HashMap(); map.put("111","蘋果手機(jī)"); map.put("222","蘋果筆記本"); return map; } }
2.服務(wù)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.問(wèn)題
1.直接使用restTemplate方式調(diào)用沒(méi)有經(jīng)過(guò)服務(wù)注冊(cè)中心獲取服務(wù)地址,代碼寫死不利于維護(hù),當(dāng)服務(wù)宕機(jī)時(shí)不能高效剔除。
2.調(diào)用服務(wù)時(shí)沒(méi)有負(fù)載均衡需要自己實(shí)現(xiàn)負(fù)載均衡策略。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
mybatis如何實(shí)現(xiàn)in傳入數(shù)組查詢
這篇文章主要介紹了mybatis如何實(shí)現(xiàn)in傳入數(shù)組查詢方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10SpringBoot設(shè)置靜態(tài)資源訪問(wèn)控制和封裝集成方案
這篇文章主要介紹了SpringBoot靜態(tài)資源訪問(wèn)控制和封裝集成方案,關(guān)于springboot靜態(tài)資源訪問(wèn)的問(wèn)題,小編是通過(guò)自定義webconfig實(shí)現(xiàn)WebMvcConfigurer,重寫addResourceHandlers方法,具體完整代碼跟隨小編一起看看吧2021-08-08java為什么使用BlockingQueue解決競(jìng)態(tài)條件問(wèn)題面試精講
這篇文章主要為大家介紹了java為什么使用BlockingQueue解決競(jìng)態(tài)條件問(wèn)題面試精講,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10