我对 Spring Web MVC 的开发人员有一个问题。
简而言之:以前可以在 HTTP DELETE 消息中发送请求正文,但现在不可能了。为什么?
详细地:
我们正在使用spring-webmvc-4.2.4.RELEASE
.
@RestController
public class Controller {
@RequestMapping(value = "/{pathVariable}/deleteAnything", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteAnything(@PathVariable String pathVariable,
@Valid @RequestBody Set<Pojo> pojoSet) {
...
我们发送
DELETE /anything/deleteAnything HTTP/1.1
Content-Type: application/json
Host: example.com
[ {
"any field" : "Any value"
} ]
并获得异常
m.m.a.RequestResponseBodyMethodProcessor : Read [java.util.Set<packagename.Pojo>] as "application/json;charset=UTF-8" with [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@333825a3]
.w.s.m.m.a.ServletInvocableHandlerMethod : Error resolving argument [1] [type=java.util.Set]
HandlerMethod details:
Controller [packagename.Controller]
Method [public org.springframework.http.ResponseEntity<?> packagename.Controller.deleteAnything(java.lang.String,java.util.Set<packagename.Pojo>)]
org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public org.springframework.http.ResponseEntity<?> packagename.Controller.deleteAnything(java.lang.String,java.util.Set<packagename.Pojo>)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:151)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:125)
...
似乎请求正文已被删除。
如果我们到处使用 HTTP POST 而不是 HTTP DELETE,它就可以正常工作。
以前它工作得很好(很抱歉我之前无法指定,因为我们的依赖关系非常复杂。如果它对你有帮助,我可以发布一个旧的build.gradle
)。
为什么现在不可能了?