Spring AOP vs AspectJ Comparison

Spring AOP vs AspectJ Comparison:

Aspect-Oriented Programming (AOP) is like Object-Oriented Programming (OOP), the key element in OOP is the class, whereas in AOP – key element is the aspect. Aspects enable the modularization of different concerns(cross-cutting concerns) such as transaction management, logging etc. that cut across multiple types and objects.

Spring-AOP Advantages

It is simpler then AspectJ, because you don’t have to use LTW (load-time weaving) or the AspectJ compiler.
You can change from spring AOP to AspectJ AOP when you use @Aspect annotation based Spring AOP.
It is proxy-based, and uses Proxy pattern and Decorator pattern to create AOP proxy

Spring-AOP Disadvantages

It is proxy-based, so only you can use method-execution point-cut.
You can’t apply Aspects when calling another method within the same class.
There can be some runtime overhead.

AspectJ Advantages

It supports all types of point-cuts. This means you can do anything.
There is some runtime overhead.

AspectJ Disadvantages

You have to be more careful to check if your aspects are weaved to only what you wanted to be weaved.
You need extra build process(using AspectJ Compiler or have to setup load-time weavin)

Gopal Das
Follow me

Leave a Reply

Your email address will not be published. Required fields are marked *