Spring Boot MVC为什么不支持POST方法?!我正在尝试实现一个简单的POST方法,用于接收一系列实体:以下是我的代码。
点击此URL链接:
@RestController(value="/backoffice/tags")
public class TagsController {
@RequestMapping(value = "/add", method = RequestMethod.POST)
public void add(@RequestBody List<Tag> keywords) {
tagsService.add(keywords);
}
}
点击此URL链接:
http://localhost:8090/backoffice/tags/add
请求正文:
[{"tagName":"qweqwe"},{"tagName":"zxczxczx"}]
我收到:
{
"timestamp": 1441800482010,
"status": 405,
"error": "Method Not Allowed",
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'POST' not supported",
"path": "/backoffice/tags/add"
}
编辑:
调试Spring Web请求处理程序
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.checkRequest(request);
protected final void checkRequest(HttpServletRequest request) throws ServletException {
String method = request.getMethod();
if(this.supportedMethods != null && !this.supportedMethods.contains(method)) {
throw new HttpRequestMethodNotSupportedException(method, StringUtils.toStringArray(this.supportedMethods));
} else if(this.requireSession && request.getSession(false) == null) {
throw new HttpSessionRequiredException("Pre-existing session required but none found");
}
}
supportedMethods
中仅有 {GET,HEAD}
两种方法。