Quick revision
The short answer
Spring AOP creates a runtime proxy around each Spring bean and can only advise method executions that are invoked through that proxy. AspectJ weaves the advice directly into the bytecode at compile time or load time, so it can advise almost any join point, including method calls, field access, constructors, private methods, self-calls and objects Spring never created. Spring AOP needs nothing beyond the container and uses AspectJ's annotations and pointcut language with a subset of its designators, which is why it is the simpler choice for most applications, while AspectJ needs a special compiler or a load-time weaving agent.
What to remember
In this answer, we saw that Spring AOP and AspectJ share a vocabulary and an annotation syntax but weave in completely different ways. Spring AOP wraps beans in runtime proxies and advises only method executions that pass through the proxy, which explains the self-call, private-method and final-class pitfalls. AspectJ rewrites bytecode at compile or load time and can advise calls, field access, constructors, private methods, self-calls and non-Spring objects, at the cost of a compiler or agent in every environment. For most applications the proxy model is enough and easier to operate.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Spring AOP creates a runtime proxy around each Spring bean and can only advise method executions that are invoked through that proxy. AspectJ weaves the advice directly into the bytecode at compile time or load time, so it can advise almost any join point, including method calls, field access, constructors, private methods, self-calls and objects Spring never created. Spring AOP needs nothing beyond the container and uses AspectJ's annotations and pointcut language with a subset of its designators, which is why it is the simpler choice for most applications, while AspectJ needs a special compiler or a load-time weaving agent.
Why this question is asked
Spring documentation uses the word AspectJ all over its AOP chapter, and @Aspect, @Before and execution(...) all come from AspectJ. So many developers assume that Spring AOP and AspectJ are the same thing. They are not, and the difference explains most of the AOP surprises we meet in Spring applications. Interviewers ask this to see whether we can say not only what each model is, but what it means for our code. In this answer, we will recap the vocabulary, look at how each model attaches advice, compare what each can advise, see what each costs to operate, and finish with when the proxy model is enough.
1A Quick Recap of the Vocabulary
An aspect is a module of cross-cutting behaviour, such as logging or transactions. A join point is a point in the running program where behaviour could be added: a method being executed, a method being called, a field being read, an object being constructed. A pointcut is an expression that selects some join points, and advice is the code that runs at the selected join points. Weaving is the act of connecting the advice to the join points.
Both models share this vocabulary. Where they differ is in when and how weaving happens, and that single difference drives everything else.
2How Spring AOP Weaves: Proxies at Runtime
Spring AOP weaves at runtime, inside the container. When it creates a bean that matches some pointcut, it wraps the bean in a proxy, either a JDK dynamic proxy implementing the bean's interfaces or a CGLIB subclass. The proxy runs the advice and forwards the call to the real object. Our class's bytecode is untouched.
This means the only join point Spring AOP can support is the execution of a method on a Spring bean, and only when the call arrives through the proxy. A self-call on this goes directly to the target and is not advised. Private, static and final methods cannot be intercepted. Objects created with new, including JPA entities, are not beans, so they are not proxied at all.
Notice that the same aspect class would also compile under AspectJ, because Spring reuses AspectJ's annotations and its pointcut parser. That shared syntax is the reason the two are often confused.
3How AspectJ Weaves: Changing the Bytecode
AspectJ weaves by changing the classes themselves. With compile-time weaving, the AspectJ compiler, ajc, compiles our code and inserts calls to the advice at each matching join point. With post-compile weaving, it does the same to existing class files or jars. With load-time weaving, a Java agent rewrites each class as the JVM loads it, using the aspects listed in META-INF/aop.xml.
Because the advice is now part of the class, there is no proxy and no way around it. A self-call is advised, because the woven code sits inside the method. A private method, a constructor, a static method and a field write are all join points AspectJ can select, using designators such as call(), get(), set(), initialization() and staticinitialization() that Spring AOP rejects. And it does not matter who creates the object: an entity built with new is woven just like a bean.
| Question | Spring AOP | AspectJ |
|---|---|---|
| How is advice attached? | runtime proxy around a bean | bytecode woven at compile or load time |
| Join points | method execution only | execution, call, field get/set, constructors, static init |
| Self-calls on this | not advised | advised |
| Private, final, static methods | not advised | advised |
| Objects not created by Spring | not advised | advised |
| Tooling needed | only the Spring container | ajc plugin or a weaving agent |
| Pointcut language | AspectJ syntax, subset of designators | full AspectJ language |
| Runtime overhead | proxy call plus interceptor chain | small, advice inlined at the join point |
4Practical Consequences in Everyday Code
The consequences show up as the familiar Spring pitfalls. @Transactional on a method called from the same class does nothing. @Cacheable on a private method does nothing. A bean whose class is final cannot get a CGLIB proxy and fails to start or silently loses its advice. Code that compares a bean's class with getClass() sees the proxy class, not ours. All of these are properties of the proxy model, and none of them exists under AspectJ.
AspectJ has its own consequences. The build needs the AspectJ plugin for Maven or Gradle, or the application must start with the weaver agent, and tests must run with the same setup or they will behave differently from production. Woven bytecode makes stack traces and debugging less direct, and IDE and tooling support is thinner than for plain Java. So we trade the proxy's predictable limits for a more powerful but heavier toolchain.
5When the Proxy Model Is Enough
For most business applications, the proxy model is enough and simpler to run. The things we usually want to add, such as transactions, caching, security checks, metrics and retries, belong at the boundary of a service, which is exactly where calls come through a proxy. When a self-call needs the behaviour, moving the method to another bean is usually also a better design.
AspectJ earns its cost when we truly need behaviour on objects Spring does not manage, such as injecting dependencies into entities with @Configurable, or on join points a proxy cannot reach, such as field access or constructors, or when proxy overhead matters in a very hot path. Spring supports that through load-time weaving and through AdviceMode.ASPECTJ on @EnableTransactionManagement and @EnableCaching.
6Follow-up questions
Does Spring AOP use the AspectJ library at all?
Yes, but only for its annotations and pointcut parsing. Spring reads @Aspect classes and evaluates execution(...) style expressions with AspectJ's parser and matcher, through the aspectjweaver jar. The weaving itself is done by Spring's proxies, not by AspectJ.
What is the difference between the call and execution join points?
execution matches the method body running, so it is seen from the callee's side, and it is the only kind Spring AOP supports. call matches the place where the method is invoked, seen from the caller's side, so AspectJ weaves the advice into every calling class. With call we can advise calls into code we cannot weave, such as JDK classes.
Can I mix the two in one application?
Yes. For example, transactions can stay proxy-based while one aspect is woven with load-time weaving for entities. It works but makes the behaviour harder to reason about, so it should be a deliberate and documented choice.
7Conclusion
In this answer, we saw that Spring AOP and AspectJ share a vocabulary and an annotation syntax but weave in completely different ways. Spring AOP wraps beans in runtime proxies and advises only method executions that pass through the proxy, which explains the self-call, private-method and final-class pitfalls. AspectJ rewrites bytecode at compile or load time and can advise calls, field access, constructors, private methods, self-calls and non-Spring objects, at the cost of a compiler or agent in every environment. For most applications the proxy model is enough and easier to operate.
Open with
The core difference is how the advice gets attached. Spring AOP does it at runtime with proxies: when the container creates a bean that matches a pointcut, it wraps it in a JDK dynamic proxy or a CGLIB subclass, and the proxy runs the advice before forwarding to the real object.
Then, if they want more
So the only join point it supports is method execution on a Spring bean, and only when the call goes through the proxy. AspectJ weaves the advice into the bytecode, either with the ajc compiler at build time, by weaving existing class files, or with a load-time weaving agent.
Since the advice is inside the class, it works on self-calls, private and static methods, constructors, field reads and writes, and objects that Spring never created, like entities. Spring AOP borrows AspectJ's annotations and pointcut syntax, but supports only a subset of the designators: execution, within, this, target, args and the annotation forms, plus its own bean designator.
The practical consequences are the usual Spring pitfalls, self-invocation, private methods, final classes and proxy types, which simply do not exist under AspectJ, while AspectJ costs you a build plugin or an agent, consistent setup in tests and harder debugging. For most services I would stay with the proxy model because the things we advise live at service boundaries anyway.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is the difference between Spring AOP's proxy model and AspectJ's model, and what...": https://scrivio-interview-library.netlify.app/spring-boot/aop/d72053d281/