Interview Prep Zoneby CuriouserLabs

Question 4 of 5 · architect level

Spring AOP vs full AspectJ — trade-offs, and when is load-time/compile-time weaving justified?

🎤 Say this first

Spring AOP: zero build/agent complexity, but method-boundary-only, public external calls, Spring beans only. AspectJ weaving modifies bytecode (at compile time via ajc, or at load time via agent) and can advise self-calls, private/static methods, constructors, field access, and non-Spring objects — at the cost of build/agent complexity, harder debugging, and a steeper team learning curve. Choose AspectJ only when the requirement demands those join points (fine-grained security auditing, legacy instrumentation, domain objects outside the container); 95% of applications never should.

The full picture

DimensionSpring AOP (proxies)AspectJ (weaving)
Join pointspublic method execution on beansmethods (any visibility), constructors, field get/set, static, self-calls
Setupnothing — it's onajc compiler or -javaagent LTW
Applies toSpring beans onlyany class the weaver touches
Runtime costone proxy hop per advised callwoven code ≈ hand-written; no proxy hop
Debugging/opsfamiliar; visible proxy in stacksynthetic methods, transformed bytecode, agent in every JVM start

Decision heuristics: if the pain is just self-invocation, restructure the beans — that's a design fix, not a weaving problem. If you need to advise domain entities (created by new, not the container), consider whether the concern belongs in a domain service instead. Legit AspectJ cases: security/audit frameworks needing field-level or constructor join points, performance instrumentation of code you don't own, and @Configurable for DI into non-managed objects. In observability specifically, the industry moved to ByteBuddy-based agents (OpenTelemetry) rather than app-level AspectJ — often the right answer is 'neither, use the agent ecosystem'.

🔄 Likely follow-up questions

  • What is @Configurable and what problem does it solve?
  • What does load-time weaving require operationally in containers/K8s?
  • How do woven aspects interact with Spring's transaction proxies if you mix both?