Java Reference
In-Depth Information
@AfterReturning(
pointcut = " CalculatorPointcuts.loggingOperation()",
returning = "result")
public void logAfterReturning(JoinPoint joinPoint, Object result) {
...
}
@AfterThrowing(
pointcut = " CalculatorPointcuts.loggingOperation()",
throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, IllegalArgumentException e) {
...
}
@Around(" CalculatorPointcuts.loggingOperation()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
...
}
}
1-13. Writing AspectJ Pointcut Expressions
Problem
Crosscutting concerns may happen at different program execution points, which are called join
points . Because of the variety of join points, you need a powerful expression language that can help
in matching them.
Solution
The AspectJ pointcut language is a powerful expression language that can match many kinds of join
points. However, Spring AOP only supports method execution join points for beans declared in its IoC
container. For this reason, only those pointcut expressions supported by Spring AOP will be introduced
here. For a full description of the AspectJ pointcut language, please refer to the AspectJ programming
guide available on AspectJ's web site ( http://www.eclipse.org/aspectj/ ).
Spring AOP makes use of the AspectJ pointcut language for its pointcut definition. Actually, Spring
AOP interprets the pointcut expressions at runtime by using AspectJ's functionality.
When writing AspectJ pointcut expressions for Spring AOP, you must keep in mind that Spring AOP
only supports method execution join points for the beans in its IoC container. If you use a pointcut
expression out of this scope, an IllegalArgumentException will be thrown.
How It Works
Method Signature Patterns
The most typical pointcut expressions are used to match a number of methods by their signatures.
For example, the following pointcut expression matches all of the methods declared in the
ArithmeticCalculator interface. The preceding wildcard matches methods with any modifier ( public ,
 
Search WWH ::




Custom Search