AspectJ plays two roles in Spring AOP. Spring reuses AspectJ's annotations (@Aspect, @Before, @Around) and its pointcut expression language to define aspects, and AspectJ itself is the optional full weaving engine you switch to when proxy-based Spring AOP is not enough. Spring AOP applies advice at runtime through proxies, while AspectJ weaves advice into bytecode at compile time, post-compile time or class-load time.
Most Spring Boot applications only use the first role: they write @Aspect classes and Spring applies them with proxies. You need real AspectJ weaving only when you must advise things proxies cannot reach, such as self-invocation, non-Spring objects or field access.
Spring AOP is a proxy-based framework. For each advised bean Spring creates a JDK dynamic proxy (when the bean implements an interface and class proxying is off) or a CGLIB subclass proxy. Callers talk to the proxy, and the proxy runs the advice before delegating to the real object.
AspectJ is a separate, complete AOP language and weaver. Spring does not replace it. It borrows from it:
@Aspect, @Pointcut, @Before, @AfterReturning, @AfterThrowing, @After and @Around annotations come from AspectJ's annotation style (org.aspectj.lang.annotation).aspectjweaver library.In a Spring Boot project the starter spring-boot-starter-aop pulls in spring-aop and aspectjweaver, and auto-configuration enables proxy-based @Aspect support for you. Outside Boot you add @EnableAspectJAutoProxy to a configuration class.
This is the common setup. The aspect is a Spring bean, and Spring applies it by proxying matching beans.
The expression language supports combining designators with &&, || and !, and named pointcuts that you can reuse. Spring AOP understands only a subset of the AspectJ designators: execution, within, this, target, args, @target, @within, @annotation, @args and Spring's own bean. Using an unsupported designator such as call or get throws an IllegalArgumentException at startup.
Because Spring AOP works through proxies, it has built-in limits:
| Limitation | Why it happens |
|---|---|
| Only Spring-managed beans are advised | Objects created with new are never proxied |
| Only method execution join points | Proxies intercept method calls, not field access, constructors or static initialisers |
| Self-invocation is not advised | this.other() bypasses the proxy, so the advice does not run |
final classes and methods cannot be advised with CGLIB | A subclass cannot override them |
private methods are not advised | They are not visible to the proxy |
| Runtime cost of a proxy call | Each advised call goes through an interceptor chain |
If you hit these limits, the usual first fix is to restructure: move the advised method into another bean, or inject the bean into itself through a proper collaborator. Full AspectJ is the fix when restructuring is not an option.
AspectJ changes the bytecode itself, so the advice is part of the class and no proxy is involved. That removes the proxy limits above and supports many more join points: constructor execution and calls, field reads and writes, static initialisation, exception handlers and calls to methods on objects that Spring does not manage.
There are three weaving styles:
ajc) compiles your sources together with your aspects, for example through the aspectj-maven-plugin or a Gradle AspectJ plugin.Spring's own features can switch to AspectJ mode. For example @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) and @EnableCaching(mode = AdviceMode.ASPECTJ) use AspectJ aspects shipped in spring-aspects, so @Transactional and @Cacheable work on self-invoked and non-proxied calls.
Provide a META-INF/aop.xml that names the aspects and the packages to weave, then start the JVM with a weaving agent, either the AspectJ weaver agent (-javaagent:aspectjweaver.jar) or Spring's instrumentation agent. Keep the weaved package list narrow, because weaving every loaded class slows startup.
| Question | Spring AOP | AspectJ weaving |
|---|---|---|
| Setup effort | Minimal, works out of the box | Needs a compiler plugin or JVM agent |
| Join points | Public method execution on beans | Methods, constructors, fields, static init |
| Self-invocation | Not advised | Advised |
| Objects outside the container | Not advised | Advised |
| Build and debugging complexity | Low | Higher, because bytecode changes |
| Typical use | Logging, security, transactions, caching on service beans | Domain-object auditing, cross-cutting rules on non-bean code |
A practical rule is to start with Spring AOP and move to AspectJ only for a concrete need that proxies cannot meet. Native-image builds (GraalVM) also favour compile-time approaches, since runtime proxy generation needs extra configuration.
It uses the AspectJ annotations and the pointcut expression matcher from aspectjweaver, but it does not weave bytecode. Advice runs through JDK or CGLIB proxies.
@Aspect in Spring Boot?No. Add spring-boot-starter-aop and annotate a bean with @Aspect. The AspectJ compiler is needed only for compile-time weaving.
That call bypasses the proxy. Move the target method into another bean, or use AspectJ weaving, which advises the code directly.
No. It supports only method execution join points on Spring beans. Use AspectJ weaving for field access, constructor and static initialiser join points.
Spring AOP gives you a simple proxy-based AOP system that borrows AspectJ's annotations and pointcut language. AspectJ proper is the full weaving engine, available at compile time, post-compile time and load time, and it removes the limits of proxies at the cost of extra build or runtime setup. Use Spring AOP by default and switch to AspectJ weaving only when you need self-invocation, non-bean objects or join points beyond method execution.