I am writing a Rest service using Spring MVC. Here is the outline of the class:
@Controller
public class MyController{
@RequestMapping(..)
public vo
Annotate your Exception Handling controller with @ControllerAdvice
instead of @Controller
.
As Boris Treukhov noted when adding the @ExceptionHandler
annotation to a method in the controller that throws the exception will make it work but only from that specific controller.
@ControllerAdvice
will allow your exception handeling methods to be applicable for your whole application not just one specific controller.