21 Dec 2017

What is the difference between Spring AOP and AspectJ AOP?


AspectJ is the industry-standard implementation for Aspect Oriented Programming whereas Spring implements AOP for some cases. Main differences between Spring AOP and AspectJ are given below....
Diagram that represent The AOP process

Spring AOP
Aspectj AOP
Spring AOP is simpler to use because we don’t need to worry about the weaving process.
In AspectJ AOP need to worry about the weaving process.
Spring AOP performs runtime weaving. This means the proxy object will be built on fly at runtime in the memory.
AspectJ AOP performs compile weaving. This means your proxy class will be available whenever you compile your code.
Spring AOP Supports only method as JoinPoints.
AspectJ AOP Supports fields, constructors, methods as JoinPoints.
Spring AOP support both static and dynamic pointcuts.
AspectJ AOP support only static pointcuts.
Spring AOP doesn’t allow annotations.
AspectJ AOP Allows annotations.
Spring AOP can be used in programmatic, Declarative xml approach, 100% code, and Sprint Boot approach.
AspectJ AOP can be used in programmatic, Declarative (xml) and annotations approach, 100% code, and Sprint Boot approach.
Advice class in Spring AOP are non-POJO classes.
Advice Classes in AspectJ AOP are POJO classes.
Can only be implemented on beans managed by Spring container.
Can be implemented on all domain objects.
No need for separate compilation process
Needs AspectJ compiler (ajc) .

Note:  from Spring 2.0 the Spring AOP is integrated with AspectJ, but it supports few features of AspectJ.
  1. Supports only method as JoinPoints.
  2. It support its own weaving module rather than AspectJ AOP.
  3. Since AspectJ does not support the Dynamic pointcut’s ,integrating with Spring AOP does not make any difference.
  4. No AspectJ compiler is required.