https://loizenai.com/restcontrolleradvice-springboot-example/
Tutorial: “@RestControllerAdvice Example SpringBoot – Error Handling for REST with Spring”.
In the article, I introduce about @RestControllerAdvice annotation of SpringBoot to handle RestAPI exception with a Github running sourcecode and details explanation example steps.
- Technologies we use in the article: – Java 1.8 – Maven – Spring Boot
@RestControllerAdvice is a new feature of Spring Framework 4.3, an annotation with combined @ControllerAdvice + @ResponseBody. So @RestControllerAdvice can help us to handle Exception with RestfulApi by a cross-cutting concern solution: @ExceptionHandler.
@Target(value=TYPE) @Retention(value=RUNTIME) @Documented @ControllerAdvice @ResponseBody public @interface RestControllerAdvice
@RestControllerAdvice is processed if an appropriate HandlerMapping-HandlerAdapter pair is configured such as the RequestMappingHandlerMapping-RequestMappingHandlerAdapter pair which are the default in the MVC Java config and the MVC namespace.