RestTemplate 无法写入请求:找不到适合请求类型 [java.util.HashMap] 的 HttpMessageConverter
RestTemplate Could not write request: no suitable HttpMessageConverter found for request type [java.util.HashMap]
我使用 Maven + Spring 4.1.0 + Java 6 我想使用 RestTemplate().postForEntity(url, request, responseType)
当我执行这段代码时:
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);
但是我有这个错误:
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,问题解决了。
我使用 Maven + Spring 4.1.0 + Java 6 我想使用 RestTemplate().postForEntity(url, request, responseType)
当我执行这段代码时:
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);
但是我有这个错误:
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,问题解决了。