詳解SpringBoot中RestTemplate的幾種實現(xiàn)
更新時間:2019年11月04日 10:29:36 作者:李海峰
這篇文章主要介紹了詳解SpringBoot中RestTemplate的幾種實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
RestTemplate的多種實現(xiàn)
使用JDK默認的http library
使用Apache提供的httpclient
使用Okhttp3
@Configuration public class RestConfig { @Bean public RestTemplate restTemplate(){ RestTemplate restTemplate = new RestTemplate(); return restTemplate; } @Bean("urlConnection") public RestTemplate urlConnectionRestTemplate(){ RestTemplate restTemplate = new RestTemplate(new SimpleClientHttpRequestFactory()); return restTemplate; } @Bean("httpClient") public RestTemplate httpClientRestTemplate(){ RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); return restTemplate; } @Bean("OKHttp3") public RestTemplate OKHttp3RestTemplate(){ RestTemplate restTemplate = new RestTemplate(new OkHttp3ClientHttpRequestFactory()); return restTemplate; } }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
spring boot實現(xiàn)超輕量級網(wǎng)關(guān)的方法(反向代理、轉(zhuǎn)發(fā))
這篇文章主要介紹了spring boot實現(xiàn)超輕量級網(wǎng)關(guān)(反向代理、轉(zhuǎn)發(fā))的相關(guān)知識,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11java.lang.IllegalStateException異常原因和解決辦法
這篇文章主要給大家介紹了關(guān)于java.lang.IllegalStateException異常原因和解決辦法,IllegalStateException是Java標準庫中的一個異常類,通常表示在不合適或無效的情況下執(zhí)行了某個方法或操作,需要的朋友可以參考下2023-07-07使用JavaConfig代替xml實現(xiàn)Spring配置操作
這篇文章主要介紹了使用JavaConfig代替xml實現(xiàn)Spring配置操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-09-09詳解SpringBoot 快速整合MyBatis(去XML化)
本篇文章主要介紹了詳解SpringBoot 快速整合MyBatis(去XML化),非常具有實用價值,需要的朋友可以參考下2017-10-10Hadoop?MapReduce實現(xiàn)單詞計數(shù)(Word?Count)
這篇文章主要為大家詳細介紹了如何利用Hadoop實現(xiàn)單詞計數(shù)(Word?Count)的MapReduce,文中的示例代碼講解詳細,感興趣的可以跟隨小編一起學(xué)習(xí)一下2023-05-05