Where is @Responsestatus annotation practical implementation covered | Spring Boot and MicroServices Forum
Sailee Naik Posted on 30/03/2020

Hi ,

In Module 4 you covered below topics and annotation theortically but i didn't find the implementaiton in the project.

@ResponseStatus, ExceptionHandlerExceptionResolver, SimpleMappingExceptionResolver, DefaultHandlerExceptionResolver, ResponseStatusExceptionResolver and @ExceptionHandler

I am currently studying module 4 , is it missing in Module 4 or is it covered in future modules which i have not yet gone through ?


Yogesh Chawla Replied on 30/03/2020

These 4(ExceptionHandlerExceptionResolver, SimpleMappingExceptionResolver, DefaultHandlerExceptionResolver and ResponseStatusExceptionResolver) are special bean types reserved for exception handling only and has got many implementations in Spring MVC.

As explained in the videos:

ExceptionHandlerExceptionResolver: It gives us a way to define exception handler methods in controller classes. Its methods are dedicated only to exception handling and they are annotated using @ExceptionHandler annotation. We have used this as part of our project.

SimpleMappingExceptionResolver: Its object need to be registered inside your configuration context file of Spring and it offers us an API where we can map one exception to a particular error page. We have added error.jsp as part of our project.

DefaultHandlerExceptionResolver: As the name suggests, it is the default implementation that is already active inside Spring MVC framework and it's available for all applications. Since we have handled exceptions by ourself so kind of we have ignored this.

ResponseStatusExceptionResolver is very similar to the DefaultHandlerExceptionResolver. The difference being is that the former works for custom exceptions.

As part of our project, we have created two custom exceptions ApplicationException.class and ApplicationExceptionHandler for AsyncRequestTimeoutException exception.

In every application, we often have a practice of writing our own custom exception classes.

Then those classes have to be annotated with @ResponseStatus annotation and also needs to be provided with an HTTP status code.

We have used this too as part of our project.