Pointcut Expressions

Learn about the pointcut expressions and gain a deeper understanding of how method calls get intercepted.

The way pointcuts are defined is important because it decides the method calls that will be intercepted. If we have two packages, we can define which method calls will be intercepted.

If we remove the last part of the package name, all calls will be intercepted.

Intercepting all method calls in a package

We have the following pointcut expression:

Press + to interact
@Before("execution(* io.datajek.springaop.movierecommenderaop.business.*.*(..))")
public void before(JoinPoint joinPoint) {
//intercept a call
logger.info("Intercepted call before execution of: {}", joinPoint);
//access check logic
}

This pointcut intercepts calls belonging to the business package. Since we used * in place of the class and method names, all calls to methods in the business package are intercepted. If we ...

Access this course and 1400+ top-rated courses and projects.