I want to customize the answer when it is a Status 405 Method Not Allowed
{
"timestamp": 1527270306717,
"status": 405,
"error": "Method Not Allowed",
"exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
"message": "Request method 'POST' not supported",
"path": "/students/Student1/courses"
}
That's the default answer and I would like to customize it and I used this and it does not work
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public String handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
System.out.println("cualquier cosa para saber si pasa por aqui");
return null;
}
On the other hand I have another Exceptionhandler and in this if it enters when it is another code like 409 or 400, and the 405 does not
@ExceptionHandler({RuntimeException.class,HttpRequestMethodNotSupportedException.class})
public ResponseEntity<ErrorDTO> processRuntimeException(HttpServletRequest req, RuntimeException ex) throws Exception {
return null;
}
Does anyone know how to solve it?