Search⌘ K
AI Features

Pointcut Expressions

Explore the use of pointcut expressions in Spring AOP to control which method calls are intercepted. Understand how to target packages, return types, specific methods, and arguments. Discover how to combine multiple pointcuts to create precise interception criteria for building modular, maintainable applications.

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:

Java
@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 change the package from business to data, ...