RestTemplate无法编写请求:找不到适合请求类型[java.util.HashMap]

时间:2019-03-12 10:57:47

标签: java spring spring-mvc java-ee resttemplate

我使用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:无法编写请求:找不到适合请求类型[java.util.HashMap]的HttpMessageConverter       在org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:310)       在org.springframework.http.converter.FormHttpMessageConverter.writeParts(FormHttpMessageConverter.java:270)       在org.springframework.http.converter.FormHttpMessageConverter.writeMultipart(FormHttpMessageConverter.java:260)       在org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:200)       在org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:1)       在org.springframework.web.client.RestTemplate $ HttpEntityRequestCallback.doWithRequest(RestTemplate.java:596)       在org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:444)       在org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)       在org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:310)

1 个答案:

答案 0 :(得分:0)

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