如何解決使用restTemplate進(jìn)行feign調(diào)用new HttpEntity<>報(bào)錯(cuò)問題
restTemplate進(jìn)行feign調(diào)用new HttpEntity<>報(bào)錯(cuò)
問題背景
今天才知道restTemplate可以直接調(diào)用feign,高級(jí)用法呀,但使用restTemplate進(jìn)行feign調(diào)用new HttpEntity<>報(bào)錯(cuò)了標(biāo)紅了
導(dǎo)入的錯(cuò)包為:
import org.apache.http.HttpEntity;
HttpEntity<>標(biāo)紅解決方案
1 原來是因?yàn)橐e(cuò)了包,在標(biāo)紅處使用快捷鍵alt+enter,選第二個(gè)改變類型
更改新包為:
import org.springframework.http.ResponseEntity;
心得
不同依賴導(dǎo)致的問題,要多注意
resttemplate調(diào)用HttpEntity 產(chǎn)生報(bào)錯(cuò)
項(xiàng)目場(chǎng)景
resttemplate調(diào)用HttpEntity 產(chǎn)生報(bào)錯(cuò)
傳輸過程
問題描述
org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [[Lorg.apache.commons.httpclient.NameValuePair;] and content type [application/x-www-form-urlencoded]
原因分析
HashMap<String, String> map = new HashMap<>(); map.put("xmlData", "xmlDataInfo"); //上面的map直接塞進(jìn)request請(qǐng)求里會(huì)報(bào)錯(cuò) /** * org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter * found for request type [[Lorg.apache.commons.httpclient.NameValuePair;] and content type [application/x-www-form-urlencoded */ //應(yīng)該把map換成NameValuePair[] data = { new NameValuePair("xmlData",string) }; NameValuePair[] data = { new NameValuePair("xmlData",string) }; HttpEntity<String> httpEntity = new HttpEntity(data, headers); //這樣就可以了
解決方案
應(yīng)該把hashmap 換成 MultiValueMap 就可以了
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- springcloud-feign調(diào)用報(bào)錯(cuò)問題
- 解決Spring調(diào)用Feign報(bào)錯(cuò):java.io.IOException:Incomplete output stream問題
- @FeignClient?path屬性路徑前綴帶路徑變量時(shí)報(bào)錯(cuò)的解決
- 通過FeignClient調(diào)用微服務(wù)提供的分頁對(duì)象IPage報(bào)錯(cuò)的解決
- 使用feign發(fā)送http請(qǐng)求解析報(bào)錯(cuò)的問題
- Springcloud?feign傳日期類型參數(shù)報(bào)錯(cuò)的解決方案
- 解決配置Feign時(shí)報(bào)錯(cuò)PathVariable annotation was empty on param 0.
相關(guān)文章
Springboot在有參構(gòu)造方法類中使用@Value注解取值
這篇文章主要介紹了Springboot在有參構(gòu)造方法類中使用@Value注解取值,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06SpringBoot接收接口入?yún)⒌姆绞叫〗Y(jié)
這篇文章主要給大家介紹了SpringBoot接收接口入?yún)⒌膸追N方式,我們從調(diào)用方的視角去看待這個(gè)問題,對(duì)調(diào)用方來說,它在調(diào)用接口時(shí)有好幾種傳參方式,下面,將會(huì)依次對(duì)這幾種參數(shù)方式進(jìn)行講解和代碼示例,需要的朋友可以參考下2024-01-01java實(shí)現(xiàn)文件導(dǎo)入導(dǎo)出
這篇文章主要介紹了java實(shí)現(xiàn)文件導(dǎo)入導(dǎo)出的方法和具體示例代碼,非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下2016-04-04Spring Boot 開發(fā)環(huán)境熱部署詳細(xì)教程
這篇文章主要介紹了Spring Boot 開發(fā)環(huán)境熱部署,本文給大家介紹了Spring Boot 開發(fā)環(huán)境熱部署的原理及快速配置方法,通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06