Bird
0
0

Why might a method annotated with @PreDestroy not be called in a Spring Boot application?

hard📝 Conceptual Q10 of 15
Spring Boot - Spring Annotations
Why might a method annotated with @PreDestroy not be called in a Spring Boot application?
ABecause the method has no parameters
BBecause the application context was not closed properly
CBecause the method is public and void
DBecause the method is annotated with @PostConstruct
Step-by-Step Solution
Solution:
  1. Step 1: Understand when @PreDestroy runs

    @PreDestroy methods run only when the Spring application context is closed properly.
  2. Step 2: Identify reasons for not running

    If the context is not closed (e.g., abrupt shutdown), @PreDestroy methods won't be called.
  3. Final Answer:

    Because the application context was not closed properly -> Option B
  4. Quick Check:

    @PreDestroy requires proper context close [OK]
Quick Trick: @PreDestroy runs only if context closes cleanly [OK]
Common Mistakes:
  • Thinking method visibility causes failure
  • Confusing @PreDestroy with @PostConstruct
  • Ignoring application context lifecycle

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes