Walk through the full bean lifecycle order from instantia… — Cracked Java
// Spring Framework & Spring Boot · Bean Scopes & Lifecycle
MidTheoryBig Tech

Walk through the full bean lifecycle order from instantiation to ready.

The bean lifecycle is a fixed, ordered chain, and knowing the exact sequence — especially that BeanPostProcessor brackets the init callbacks — is the heart of this question. The container drives every step; your code only plugs into the hooks.

Creation order (instantiation to ready)

  1. Instantiate — Spring calls the constructor (or factory method). Constructor injection happens here.
  2. Populate properties — field/setter dependency injection runs; @Autowired fields and setters are filled.
  3. Aware callbacks — in order: BeanNameAware.setBeanName, BeanFactoryAware.setBeanFactory, then ApplicationContextAware.setApplicationContext.
  4. BeanPostProcessor.postProcessBeforeInitialization — every registered BPP gets a crack at the instance before init callbacks. (This is where @PostConstruct is actually triggered, via CommonAnnotationBeanPostProcessor.)
  5. @PostConstruct — your annotated init method.
  6. InitializingBean.afterPropertiesSet() — if the bean implements it.
  7. Custom init-method — declared via @Bean(initMethod=...) or XML.
  8. BeanPostProcessor.postProcessAfterInitialization — runs after init. AOP proxies (e.g. @Transactional) are created here, so the object handed out can be a proxy wrapping your bean.
  9. Ready — the bean is fully initialized and cached (for singletons).
@Component
public class Engine implements InitializingBean {
    @PostConstruct void warmUp() { }          // step 5
    public void afterPropertiesSet() { }       // step 6 — runs after warmUp()
}

Destruction order (reverse-ish)

On context shutdown, for singletons only:

  1. @PreDestroy — your annotated cleanup method.
  2. DisposableBean.destroy().
  3. Custom destroy-method.
START  -> @PostConstruct -> afterPropertiesSet() -> initMethod
SHUTDOWN -> @PreDestroy   -> destroy()           -> destroyMethod

Mark your status