【发布时间】:2019-03-12 10:57:46
【问题描述】:
我使用 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:无法写入请求:没有找到适合请求类型的 HttpMessageConverter [java.util.HashMap] 在 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)
【问题讨论】:
-
你定义了任何转换器吗?也可以分享您的弹簧配置
-
谢谢,但即使使用转换器,它也不起作用:(
标签: java spring spring-mvc jakarta-ee resttemplate