Skip to main content

AOP and Proxies

Cert Focus

You should understand why Spring uses proxies and how AOP relates to transactions, security, caching, and async behavior.

Must Know

  • AOP separates cross-cutting concerns from business logic.
  • An aspect contains advice and pointcuts.
  • Advice is code that runs at a matched join point.
  • A pointcut selects where advice applies.
  • Spring AOP is proxy-based.
  • JDK proxies proxy interfaces.
  • CGLIB proxies classes.
  • Self-invocation bypasses the proxy.

Exam Trap

Proxy-based features only apply when the call goes through the Spring proxy.

Self-Check

  • Can I explain aspect, advice, pointcut, and join point?
  • Can I explain JDK proxy vs CGLIB proxy?
  • Can I explain self-invocation?
  • Can I name Spring features that commonly depend on proxies?
Model Answers

An aspect contains cross-cutting behavior. Advice is the code that runs. A pointcut selects where the advice applies. A join point is a point in execution where advice can apply.

JDK dynamic proxies proxy interfaces. CGLIB proxies classes by creating subclasses.

Self-invocation means one method in a class calls another method on the same object. That call bypasses the Spring proxy, so proxy-based behavior may not run.

Common proxy-based features include @Transactional, method security, @Cacheable, @Async, and many AOP advices.

Memory Sentence

Spring AOP works when methods are called through a proxy.