Bird
0
0

Which of the following best describes the @PreDestroy annotation in Spring Boot?

easy📝 Conceptual Q2 of 15
Spring Boot - Spring Annotations
Which of the following best describes the @PreDestroy annotation in Spring Boot?
AIt marks a method to run before the bean is destroyed
BIt marks a method to run after the bean is created
CIt marks a method to run when the bean is accessed
DIt marks a method to run during bean initialization
Step-by-Step Solution
Solution:
  1. Step 1: Understand bean destruction in Spring

    When the application context closes, beans are destroyed.
  2. Step 2: Role of @PreDestroy

    The method annotated with @PreDestroy runs just before the bean is removed from the context.
  3. Final Answer:

    It marks a method to run before the bean is destroyed -> Option A
  4. Quick Check:

    @PreDestroy = runs before bean destruction [OK]
Quick Trick: @PreDestroy runs cleanup before bean removal [OK]
Common Mistakes:
  • Confusing @PreDestroy with @PostConstruct
  • Thinking it runs after bean destruction
  • Assuming it runs multiple times

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes