AOP With Spring Framework
AOP With Spring Framework
The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity
is the aspect. Dependency Injection helps you decouple your application objects from
each other and AOP helps you decouple cross-cutting concerns from the objects that
they affect. AOP is like triggers in programming languages such as Perl, .NET, Java,
and others.
AOP Terminologies
Before we start working with AOP, let us become familiar with the AOP concepts and
terminology. These terms are not specific to Spring, rather they are related to AOP.
Aspect
This is a module which has a set of APIs providing cross-cutting
1 requirements. For example, a logging module would be called AOP aspect
for logging. An application can have any number of aspects depending on
the requirement.
Join point
This represents a point in your application where you can plug-in the AOP
2
aspect. You can also say, it is the actual place in the application where an
action will be taken using Spring AOP framework.
3 Advice
This is the actual action to be taken either before or after the method
execution. This is an actual piece of code that is invoked during the
https://www.tutorialspoint.com/spring/aop_with_spring.htm 1/3
4/21/24, 9:38 AM AOP with Spring Framework
Pointcut
This is a set of one or more join points where an advice should be
4
executed. You can specify pointcuts using expressions or patterns as we
will see in our AOP examples.
Introduction
5 An introduction allows you to add new methods or attributes to the
existing classes.
Target object
6 The object being advised by one or more aspects. This object will always
be a proxied object, also referred to as the advised object.
Weaving
Weaving is the process of linking aspects with other application types or
7
objects to create an advised object. This can be done at compile time,
load time, or at runtime.
Types of Advice
Spring aspects can work with five kinds of advice mentioned as follows −
before
1
Run advice before the a method execution.
after
2
Run advice after the method execution, regardless of its outcome.
after-returning
3 Run advice after the a method execution only if method completes
successfully.
after-throwing
4 Run advice after the a method execution only if method exits by throwing
an exception.
around
5
Run advice before and after the advised method is invoked.
https://www.tutorialspoint.com/spring/aop_with_spring.htm 2/3
4/21/24, 9:38 AM AOP with Spring Framework
@AspectJ based
2 @AspectJ refers to a style of declaring aspects as regular Java classes
annotated with Java 5 annotations.
https://www.tutorialspoint.com/spring/aop_with_spring.htm 3/3