In che modo il metodo POST non può essere supportato da Spring Boot MVC?! Sto cercando di implementare un metodo semplice post che accetta un elenco delle entità: Ecco il mio codiceSpring Boot 405 Il metodo POST non è supportato?
@RestController(value="/backoffice/tags")
public class TagsController {
@RequestMapping(value = "/add", method = RequestMethod.POST)
public void add(@RequestBody List<Tag> keywords) {
tagsService.add(keywords);
}
}
Colpire questo URL come questo:
http://localhost:8090/backoffice/tags/add
Richiesta Corpo:
[{"tagName":"qweqwe"},{"tagName":"zxczxczx"}]
Ricevo:
{
"timestamp": 1441800482010,
"status": 405,
"error": "Method Not Allowed",
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'POST' not supported",
"path": "/backoffice/tags/add"
}
EDIT:
Debugging Primavera Web gestore richieste
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");
}
}
Gli unici due metodi in supportedMethods
sono {GET,HEAD}
aggiornare il Codice TagsController pure. –
Considera di tornare alla revisione 2.In questo momento, il codice nella tua domanda è corretto, rendendo la risposta priva di significato. – approxiblue
@RafalG. il codice in questione non dovrebbe essere "riparato", rompe la domanda. – eis