Hands-On High Performance with Spring 5
上QQ阅读APP看书,第一时间看更新

Defining pointcuts

As we learned before, pointcuts define a point where advice should be applied. Spring AOP uses AspectJ's expression language to define a point where advice should be applied. The following are the set of pointcut designators supported in Spring AOP:

Let's see how to write the point expression using the execution designator:

  • Using execution(<method-pattern>): Method matching to the pattern would be advised. The following is the method pattern:
[Modifiers] ReturnType [ClassType]
MethodName ([Arguments]) [throws ExceptionType]
  • To create composite pointcuts by joining other pointcuts, we can use the &&, ||, and ! operators (these mean AND, OR, and NOT, respectively).

In the preceding method pattern, anything defined in [ ] is optional. Values without [ ] are mandatory to define.

The following diagram will illustrate point expression using the execution designator to apply advice whenever the findAccountById() method is executed:

Execution join point pattern