Bird
0
0

What happens when a method annotated with @PostConstruct is used in a Spring Boot bean?

easy📝 Conceptual Q1 of 15
Spring Boot - Spring Annotations
What happens when a method annotated with @PostConstruct is used in a Spring Boot bean?
AIt runs before the bean is created
BIt runs once after the bean is fully initialized
CIt runs every time the bean is accessed
DIt runs only when the bean is destroyed
Step-by-Step Solution
Solution:
  1. Step 1: Understand the lifecycle of a Spring bean

    The bean is created and dependencies are injected first.
  2. Step 2: Role of @PostConstruct

    The method annotated with @PostConstruct runs once after the bean is fully initialized but before it is used.
  3. Final Answer:

    It runs once after the bean is fully initialized -> Option B
  4. Quick Check:

    @PostConstruct = runs after initialization [OK]
Quick Trick: @PostConstruct runs once after bean setup completes [OK]
Common Mistakes:
  • Thinking @PostConstruct runs before bean creation
  • Confusing @PostConstruct with @PreDestroy
  • Assuming it runs multiple times

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes