The full picture
🎬 AOP: how the proxy intercepts a call
1 / 5The controller injects OrderService — but Spring actually injected a PROXY that wraps the real object. Calls to orderService.place() hit the proxy first.
- Where proxies are born:
postProcessAfterInitializationin the auto-proxy creator — late enough that the proxy wraps the fully initialized bean. - Weaving spectrum: Spring AOP = runtime proxies (no bytecode modification); AspectJ = compile-time or load-time weaving (modifies the class itself — can advise private methods, field access, constructors, self-calls).
- @Transactional flow: proxy →
TransactionInterceptor→PlatformTransactionManager.getTransaction()(begin/join per propagation) → target method → commit, or rollback on rule-matching exception. - Ordering: multiple aspects nest by
@Order— e.g., security outside transaction outside retry, and getting that order wrong is a real production bug (retrying inside a doomed transaction).