Bird
0
0

Which annotation is used in Spring Boot to create a centralized error handler class?

easy📝 Syntax Q12 of 15
Spring Boot - Exception Handling
Which annotation is used in Spring Boot to create a centralized error handler class?
A@ControllerAdvice
B@Service
C@RestController
D@Repository
Step-by-Step Solution
Solution:
  1. Step 1: Identify the annotation for centralized error handling

    @ControllerAdvice is the Spring Boot annotation designed to handle exceptions globally across controllers.
  2. Step 2: Eliminate other annotations

    @RestController is for REST endpoints, @Service is for business logic, and @Repository is for data access, none handle errors globally.
  3. Final Answer:

    @ControllerAdvice -> Option A
  4. Quick Check:

    @ControllerAdvice = centralized error handler [OK]
Quick Trick: Remember: Advice means giving guidance globally [OK]
Common Mistakes:
  • Using @RestController for error handling
  • Confusing @Service with error handling
  • Thinking @Repository handles exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes