Pointcuts

In AOP, a pointcut is a predate that matches join points. The value of the @Around annotation, "execution(* app.messages..*.*(..))"from the preceding example is a pointcut expression, which specifies when the checkSecurity() around advice should be fired. You can also use the @Pointcut annotation to declare a pointcut signature, as follows:

@Aspect
@Component
public class SecurityChecker {

@Pointcut("execution(* app.messages..*.*(..))")
public void everyMessageMethod() {}

@Around("everyMessageMethod()")
public Object checkSecurity (ProceedingJoinPoint joinPoint) {
...
}
}

In the SecurityChecker aspect, we create an everyMessageMethod() public method and annotate it with the @Pointcut annotation. Since we only define a pointcut signature here, this method has no return value and is empty. In the @Around annotation of the checkSecurity() method, we use this method as a pointcut expression.

The execution in the previous pointcut expression is a pointcut designator (PCD), which tells Spring AOP what to match. Another useful PCD is @annotation. With this PCD, instead of using a regular expression to match join points, you can match only those methods annotated with a specific annotation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.125.51