What happens between "the container starts" and "your bean is ready" — and how Spring slips extra behaviour in without you seeing it.
@Value, @PostConstruct, AOP, @Transactional, @Repository
translation — all of them. Understand the lifecycle and these stop being magic.
Memorise this sequence — the exam asks "what runs first/last" repeatedly:
${...}) before any bean exists@Autowired)BeanNameAware, BeanFactoryAware, ApplicationContextAwarepostProcessBeforeInitialization@PostConstructInitializingBean.afterPropertiesSet()init-methodpostProcessAfterInitialization ← proxies are created hereThen at shutdown: @PreDestroy → DisposableBean.destroy() → custom destroy-method.
(Recall from Lesson 4: prototype beans get none of these destroy callbacks.)
BeanFactoryPostProcessor (BFPP) | BeanPostProcessor (BPP) | |
|---|---|---|
| Operates on | Bean definitions (metadata) | Bean instances (objects) |
| When | Before any bean is instantiated | Around each bean's initialization (before & after) |
| Runs… | First | After all BFPPs |
| Classic example | PropertySourcesPlaceholderConfigurer (resolves ${...}) | AutowiredAnnotationBeanPostProcessor (@Autowired/@Value); the AOP auto-proxy creator |
ApplicationContext.
That last BPP step (postProcessAfterInitialization) is where Spring can return a proxy
wrapping your bean instead of the bean itself. The proxy intercepts calls and runs extra logic — transactions,
security, AOP advice — around your real method.
| Proxy type | Used when | How | Limitation |
|---|---|---|---|
| JDK dynamic proxy | Target implements an interface | Proxy implements the same interface | Only interface methods are advised |
| CGLIB | No interface (or proxyTargetClass=true) | Proxy subclasses the target | Class & methods must not be final |
this.other(), that call never leaves the object, so the proxy is
bypassed and its advice (e.g. a @Transactional(REQUIRES_NEW) on other()) does
not run. This is the single most common AOP/transaction bug — and a favourite exam question.
@DependsOn("otherBean") to force a bean to be created after named beans.@Order is not for creation order — it orders items within a collection (e.g. a List of beans, or AOP advisor precedence), not the sequence of bean creation.NoUniqueBeanDefinitionException at startup. Resolve with @Primary on the default,
or @Qualifier at the injection point (Lesson 3).
Read "Customizing beans using a BeanPostProcessor", "Customizing configuration metadata with a BeanFactoryPostProcessor", and "Lifecycle Callbacks".
The BFPP-vs-BPP distinction and self-invocation are the highest-value questions here. Options shuffle on every load.
@DependsOn/creation-order items.
Re-run the Container Drill — you've now covered every concept in it.