Spring @ControllerAdvice Annotation Example
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBA3B-jJjIXX54vAGivl23x51t_xFsv53JQXz0S7617Syj0mfW0muKTJsq08ZL2hOBqLn9wlpqcP7zeWjGzx_h3s4vTYXh2FuE1b76CiMMLJRIY_wEirxd9VEr0n_VrCPuC7WnaEE0QKMDAZlqLpZ2wkBc4T7j_RqA1pyRuxb2aV0wMkWLnphbj-zMsA/w400-h215/Untitled%20Diagram.drawio%20(5).png)
In this section we will learn about @ControllerAdvice Annotation. The @ControllerAdvice is a specialization of the @Component annotation which sanctions to handle exceptions across the whole application in one global handling component. It can be viewed as an interceptor of exceptions thrown by methods annotated with @RequestMapping and kindred. It declares @ExceptionHandler , @InitBinder , or @ModelAttribute methods to be shared across multiple @Controller classes. ResponseEntityExceptionHandler is a convenient base class for @ControllerAdvice classes that wish to provide centralized exception handling across all @RequestMapping methods through @ExceptionHandler methods. It provides an methods for handling internal Spring MVC exceptions. It returns a ResponseEntity in contrast to DefaultHandlerExceptionResolver which returns a ModelAndView . The following example creates a Spring Boot web application which uses @ControllerAdvice . Project Directory Pom.xml <? xml ve