Jak metoda POST może nie być obsługiwana przez Spring Boot MVC?! Próbuję zaimplementować proste metody POST, który akceptuje listę podmiotów: tutaj jest mój kodMetoda Spring Boot 405 POST nie jest obsługiwana?
@RestController(value="/backoffice/tags")
public class TagsController {
@RequestMapping(value = "/add", method = RequestMethod.POST)
public void add(@RequestBody List<Tag> keywords) {
tagsService.add(keywords);
}
}
Uderzanie ten URL tak:
http://localhost:8090/backoffice/tags/add
Zapytanie ciała:
[{"tagName":"qweqwe"},{"tagName":"zxczxczx"}]
Otrzymuję:
{
"timestamp": 1441800482010,
"status": 405,
"error": "Method Not Allowed",
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'POST' not supported",
"path": "/backoffice/tags/add"
}
EDIT:
debugowanie Wiosna Web Zapytanie Handler
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");
}
}
Tylko dwie metody supportedMethods
są {GET,HEAD}
Aktualizacja kod TagsController również. –
Rozważ przeniesienie do wersji 2.W tej chwili kod w twoim pytaniu jest poprawny, co sprawia, że odpowiedź jest bez znaczenia. – approxiblue
@RafalG. kod, o którym mowa, nie powinien być "naprawiony", łamie to pytanie. – eis