Bird
0
0

What will happen if a Spring bean implements InitializingBean and overrides afterPropertiesSet()?

medium📝 component behavior Q5 of 15
Spring Boot - Inversion of Control and Dependency Injection
What will happen if a Spring bean implements InitializingBean and overrides afterPropertiesSet()?
AafterPropertiesSet() is called before bean instantiation
BafterPropertiesSet() is called after dependency injection
CafterPropertiesSet() is called during bean destruction
DafterPropertiesSet() is never called automatically
Step-by-Step Solution
Solution:
  1. Step 1: Recall InitializingBean behavior

    afterPropertiesSet() runs after dependencies are injected to allow custom initialization.
  2. Step 2: Confirm lifecycle timing

    This method is called before the bean is ready but after injection, not before instantiation or during destruction.
  3. Final Answer:

    afterPropertiesSet() is called after dependency injection -> Option B
  4. Quick Check:

    afterPropertiesSet() runs post-injection [OK]
Quick Trick: afterPropertiesSet() runs after dependencies injection [OK]
Common Mistakes:
  • Confusing with destroy methods
  • Thinking it runs before instantiation
  • Assuming manual invocation needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes