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.
Loading...
Related Quiz
- In a Spring Cloud environment, to configure a service to discover its peers using Eureka, the property ____ must be defined in the application's properties or YAML file.
- In a Spring Boot project, which file is primarily used to declare project dependencies?
- To enable method-level security in Spring Security, the _____ annotation must be added to the configuration class.
- In Spring Boot, _____ annotation is used to map HTTP POST requests onto specific handler methods.
- In Spring Boot, which annotation is primarily used to perform Bean Validation on fields?