Java Reference
In-Depth Information
protected , and private ) and any return type. The two dots in the argument list match any number of
execution(* com.apress.springenterpriserecipes.calculator.
You can omit the package name if the target class or interface is located in the same package as
this aspect.
execution(* ArithmeticCalculator.*(..))
The following pointcut expression matches all the public methods declared in the
ArithmeticCalculator interface:
execution( public * ArithmeticCalculator.*(..))
You can also restrict the method return type. For example, the following pointcut matches the
methods that return a double number:
execution(public double ArithmeticCalculator.*(..))
The argument list of the methods can also be restricted. For example, the following pointcut
matches the methods whose first argument is of primitive double type. The two dots then match any
number of followed arguments.
execution(public double ArithmeticCalculator.*( double, ..))
Or, you can specify all the argument types in the method signature for the pointcut to match.
execution(public double ArithmeticCalculator.*( double, double))
Although the AspectJ pointcut language is powerful in matching various join points, sometimes
you might not be able to find any common characteristics (e.g., modifiers, return types, method name
patterns, or arguments) for the methods you want to match. In such cases, you can consider providing a
custom annotation for them. For instance, you can define the following annotation type (this annotation
can be applied to both method level and type level):
package com.apress.springenterpriserecipes.calculator;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target( { ElementType.METHOD, ElementType.TYPE })
public @interface LoggingRequired {
Then you can annotate all methods that require logging with this annotation. Note that the
annotations must be added to the implementation class but not the interface because they will not
be inherited.
Search WWH ::

Custom Search