简体   繁体   中英

RestTemplate Could not write request: no suitable HttpMessageConverter found for request type [java.util.HashMap]

I use Maven + Spring 4.1.0 + Java 6 and I want use RestTemplate().postForEntity(url, request, responseType)

while I execute this code :

HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<MultiValueMap<String, Object>>(parameters, headers);
final RestTemplate restTemplate = RestTemplateUtils.createHttpTemplate();
ResponseEntity<String> response = restTemplate.postForEntity(url, entity,
            String.class);

but I have this error:

org.springframework.http.converter.HttpMessageNotWritableException: Could not write request: no suitable HttpMessageConverter found for request type [java.util.HashMap] at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:310) at org.springframework.http.converter.FormHttpMessageConverter.writeParts(FormHttpMessageConverter.java:270) at org.springframework.http.converter.FormHttpMessageConverter.writeMultipart(FormHttpMessageConverter.java:260) at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:200) at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:1) at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:596) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:444) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409) at org.springframework.web. client.RestTemplate.postForEntity(RestTemplate.java:310)

该问题是由于旧的Spring版本导致的,因此需要迁移到Spring版本4,此问题已解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM