Aspect
An aspect in Java is a class that encapsulates cross-cutting concerns, such as logging or transaction management. It is identified by the @Aspect
annotation and defines the types of methods to intercept and the actions to take upon interception. Aspects enable the modularization of cross-cutting concerns, allowing developers to apply them consistently across different parts of an application. They can handle various concerns like logging, performance monitoring, or transaction management that span multiple layers of an application.
Pointcut
Pointcuts are expressions that specify the criteria for selecting join points in the application where advice should be applied. They determine which method calls or other join points will be intercepted and when advice should be executed. Pointcuts are defined using a specific syntax and should be carefully crafted to target the desired set of join points while avoiding unnecessary interception, as they directly impact the behavior of the aspect.
Advice
The tasks performed after intercepting a method call are called advice. It is the logic of the methods in a class marked with @Aspect
. Advices are basically the methods that get executed when a method calls meets a pointcut. These methods can get executed before, around the time of, or after the execution of the intercepted method call. There are different advice types as shown below.
Get hands-on with 1400+ tech skills courses.