怎麼可能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