Bird
0
0

Given a Spring bean with a method annotated @PostConstruct, what will happen when the bean is created?

medium📝 component behavior Q4 of 15
Spring Boot - Inversion of Control and Dependency Injection
Given a Spring bean with a method annotated @PostConstruct, what will happen when the bean is created?
AThe method will be called after dependencies are injected
BThe method will be called before the bean is instantiated
CThe method will be called after the bean is destroyed
DThe method will never be called automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand @PostConstruct timing

    @PostConstruct methods run after dependency injection but before the bean is ready for use.
  2. Step 2: Match lifecycle event with method call

    The annotated method is called automatically after dependencies are set, not before instantiation or after destruction.
  3. Final Answer:

    The method will be called after dependencies are injected -> Option A
  4. Quick Check:

    @PostConstruct runs post-injection [OK]
Quick Trick: @PostConstruct runs after dependencies injection [OK]
Common Mistakes:
  • Thinking it runs before instantiation
  • Confusing with @PreDestroy
  • Assuming manual call is needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes