SteelReed

Search

Search posts, questions…

Spring BootQuestion 7 / 26

Middle

What are the steps of a bean's lifecycle? How do BeanPostProcessor and BeanFactoryPostProcessor differ?

Short answer

A bean goes definition → instantiation → injection → callbacks → postProcessAfterInitialization (where AOP proxies are made) → ready → @PreDestroy. BeanFactoryPostProcessor edits metadata before any bean exists; BeanPostProcessor handles each instance.

BeanFactoryPostProcessorBean definitionInstantiate + inject*Aware callbacksBPP before-init@PostConstructBPP after-initAOP proxy createdReady, then @PreDestroy

3 points to say:

  1. Order: definition → instance → inject → Aware → before-init → @PostConstruct → after-init (proxy).
  2. BFPP edits definitions before any bean exists; BPP modifies or wraps each instance.
  3. @PostConstruct runs on the raw object, before the proxy; heavy startup work goes in a runner or ApplicationReadyEvent.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.