springcloud-基於RestTemplate的服務調用


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.調用服務時沒有負載均衡需要自己實現負載均衡策略。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM