How many ways to handle exceptions in the Spring MVC Framework?
Spring MVC Framework provides two ways for handling the exceptions:
- Using XML configuration: this configuration is similar to the exception handling in Servlet/JSP, by calling a SimpleMappingExceptionResolver bean in the context file of Spring's application and the type of map execution with the view names. This approach simply applies to all the controllers in the application.
- Using exception handler method: The annotation type “@ExceptionHandler" provided by Spring is being used to annotate the method to handle the exceptions raised by the controller's methods. This approach applies to only the controllers in the application where the handler method is declared.
BY Best Interview Question ON 03 May 2022