In Spring Boot, which annotation is used to define a class as a global advice for all controllers?

  • @Controller
  • @RestController
  • @ControllerAdvice
  • @GlobalAdvice
In Spring Boot, the @ControllerAdvice annotation is used to define a class as global advice for all controllers. This class can contain methods annotated with @ExceptionHandler, @InitBinder, or @ModelAttribute, which are applied globally to controllers. It's a crucial mechanism for adding cross-cutting concerns, such as exception handling, to your Spring Boot application. The other options are not used for this purpose.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *