RestTemplate 模組間的通訊

2022-08-23 12:06:15 字數 990 閱讀 8245

1.第一種方式(直接使用resttemplate ,和url的純路徑獲取不同模組的服務)

缺點,太死板。不能靈活在各個模組間切換

2.第二種方式(通過loadbalancerclient獲取應用名,然後根據應用名獲取url,最後根據resttemplate通過url和返回值獲得資訊)resttemplate resttemplate = new resttemplate();

3.第三種方式

(利用註解@loadbalanced,可在resttemplate裡使用應用名字 )這其中使用了負載均衡(隨機,輪詢。。。)

先把resttemplate注入bean容器然後

ribbon的負載均衡

模組間依賴引用

例如 hutool元件在各個模組都很大機率被用到,所以筆者直接將其沉在common模組。屆時無論哪個模組使用都不需要引用 專案模組引用 com.jarjar groupid mallcloud common artifactid version 此處方便模組版本管理,直接引用了頂層pom專案版本。不...

RestTemplate使用總結

resttemplate的介紹就不說了,總的來說用這個物件可以很方便的模擬乙個http請求。talk is cheap,show me the code,使用的是springboot整合的工程所以以下涉及到的物件都是註解式的宣告和注入,一 宣告resttemplate物件 當然,可以利用註解 bea...

RestTemplate使用總結

resttemplate的介紹就不說了,總的來說用這個物件可以很方便的模擬乙個http請求。talk is cheap,show me the code,使用的是springboot整合的工程所以以下涉及到的物件都是註解式的宣告和注入,一 宣告resttemplate物件 當然,可以利用註解 bea...