Java Reference
In-Depth Information
+ Arrays.toString(joinPoint.getArgs()) + " in "
+ joinPoint.getSignature().getName() + "()");
throw e;
The around advice type is very powerful and flexible in that you can even alter the original argument
values and change the final return value. You must use this type of advice with great care because the
call to proceed with the original join point may easily be forgotten.
Tip A common rule for choosing an advice type is to use the least powerful one that can satisfy your
1-12. Reusing Pointcut Definitions
When writing AspectJ aspects, you can directly embed a pointcut expression in an advice annotation.
However, the same pointcut expression may be repeated in multiple advices.
Like many other AOP implementations, AspectJ also allows you to define a pointcut independently to be
reused in multiple advices.
How It Works
In an AspectJ aspect, a pointcut can be declared as a simple method with the @Pointcut annotation. The
method body of a pointcut is usually empty because it is unreasonable to mix a pointcut definition with
application logic. The access modifier of a pointcut method controls the visibility of this pointcut as well.
Other advices can refer to this pointcut by the method name.
package com.apress.springenterpriserecipes.calculator;
import org.aspectj.lang.annotation.Pointcut;
public class CalculatorLoggingAspect {
@Pointcut("execution(* *.*(..))")
private void loggingOperation() {}
@Before(" loggingOperation()")
public void logBefore(JoinPoint joinPoint) {
Search WWH ::

Custom Search