execution(modifiers-pattern? return-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)
如:execution(public int com.apress.springrecipes.calculator.ArithmeticCalculator.*(..))
@LoggingRequired public class ArithmeticCalculatorImpl implements ArithmeticCalculator { ... }
使用表達式:@within(com.apress.springrecipes.calculator.LoggingRequired)匹配ArithmeticCalculatorImpl中全部方法。
bean(*Calculator)
匹配全部已經Calculator結尾的bean。
@Aspect public class CalculatorPointcuts { @Pointcut("within(ArithmeticCalculator+)") public void arithmeticOperation() {} @Pointcut("within(UnitCalculator+)") public void unitOperation() {} @Pointcut("arithmeticOperation() || unitOperation()") public void loggingOperation() {} }
@Aspect public class CalculatorPointcuts { ... ... @Pointcut("execution(* *.*(..)) && target(target) && args(a,b)") public void parameterPointcut(Object target, double a, double b) {} }
@Aspect public class CalculatorLoggingAspect { ... ... @Before("CalculatorPointcuts.parameterPointcut(target, a, b)") public void logParameter(Object target, double a, double b) { log.info("Target class : " + target.getClass().getName()); log.info("Arguments : " + a + ", " + b); } }