Java Reference
In-Depth Information
@AfterReturning(
pointcut = " loggingOperation()",
returning = "result")
public void logAfterReturning(JoinPoint joinPoint, Object result) {
...
}
@AfterThrowing(
pointcut = " loggingOperation()",
throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, IllegalArgumentException e) {
...
}
@Around(" loggingOperation()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
...
}
}
Usually, if your pointcuts are shared between multiple aspects, it is better to centralize them in a
common class. In this case, they must be declared as public .
package com.apress.springenterpriserecipes.calculator;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class CalculatorPointcuts {
@Pointcut("execution(* *.*(..))")
public void loggingOperation() {}
}
When you refer to this pointcut, you have to include the class name as well. If the class is not located
in the same package as the aspect, you have to also include the package name.
package com.apress.springenterpriserecipes.calculator;
...
@Aspect
public class CalculatorLoggingAspect {
...
@Before(" CalculatorPointcuts.loggingOperation()")
public void logBefore(JoinPoint joinPoint) {
...
}
Search WWH ::




Custom Search