怎么可能POST方法不被Spring Boot MVC支持?我想实现一个接受实体列表一个简单的POST方法:这里是我的代码Spring Boot 405不支持POST方法?
@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}
更新TagsController的代码。 –
考虑回滚到修订2。现在,你的问题中的代码是正确的,使答案毫无意义。 – approxiblue
@RafalG。有关的代码不应该是“固定的”,它打破了这个问题。 – eis