Spring Boot & Microservices (50 Qs)•Part 1: Spring Core, Auto-Configuration & Architecture (1 - 10)
Walk through the Spring Bean Lifecycle.
senior LevelLifecycleSystem Design
In Simple Words:
- Instantiation: JVM creates bean instance via constructor.
- Populate Properties: Dependencies injected via setters/constructors.
- Aware Interfaces: Spring injects container references (
BeanNameAware,ApplicationContextAware). - BeanPostProcessor (Before Init):
postProcessBeforeInitializationcalled. - Initialization:
@PostConstructmethod, followed byInitializingBean.afterPropertiesSet(), followed by custominitMethod. - BeanPostProcessor (After Init):
postProcessAfterInitialization(AOP proxies created here). - Ready for Use: Bean is live and serves traffic.
- Destruction:
@PreDestroymethod, followed byDisposableBean.destroy().