Top Description Fields Methods
org.springframework.aop

public Interface MethodMatcher

Known Direct Subinterfaces
org.springframework.aop.IntroductionAwareMethodMatcher
Known Direct Implementers
org.springframework.aop.TrueMethodMatcher, org.springframework.aop.support.DynamicMethodMatcher, org.springframework.aop.support.ControlFlowPointcut, org.springframework.aop.support.MethodMatchers.UnionMethodMatcher, org.springframework.aop.support.MethodMatchers.IntersectionMethodMatcher, org.springframework.aop.support.MethodMatchers.NegateMethodMatcher, org.springframework.aop.support.StaticMethodMatcher
Imports
java.lang.reflect.Method

Part of a Pointcut: Checks whether the target method is eligible for advice.

A MethodMatcher may be evaluated statically or at runtime (dynamically). Static matching involves a method and (possibly) method attributes. Dynamic matching also makes arguments for a particular call available, and any effects of running previous advice applying to the joinpoint.

If an implementation returns false from its isRuntime() method, evaluation can be performed statically, and the result will be the same for all invocations of this method, whatever their arguments. This means that if the isRuntime() method returns false, the 3-arg matches(Method, Class, Object[]) method will never be invoked.

If an implementation returns true from its 2-arg matches(Method, Class) method and its isRuntime() method returns true, the 3-arg matches(Method, Class, Object[]) method will be invoked immediately before each potential execution of the related advice to decide whether the advice should run. All previous advice, such as earlier interceptors in an interceptor chain, will have run, so any state changes they have produced in parameters or ThreadLocal state will be available at the time of evaluation.

Warning

Concrete implementations of this interface must provide proper implementations of Object#equals(Object), Object#hashCode(), and Object#toString() in order to allow the matcher to be used in caching scenarios — for example, in proxies generated by CGLIB. As of Spring Framework 6.0.13, the toString() implementation must generate a unique string representation that aligns with the logic used to implement equals(). See concrete implementations of this interface within the framework for examples.

Authors
Rod Johnson, Sam Brannen
Since
11.11.2003
See Also
Pointcut, ClassFilter

Field Summary

Modifier and TypeField and Description
public static final MethodMatcher
TRUE

Canonical instance of a MethodMatcher that matches all methods.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

whether a runtime match via matches(Method, Class, Object[]) is required if static matching passed
isRuntime
()

Is this MethodMatcher dynamic, that is, must a final check be made via the matches(Method, Class, Object[]) method at runtime even if matches(Method, Class) returns true?

public boolean

Returns:

whether this method matches statically
matches
(Method
the candidate method
method
,
Class<?>
the target class
targetClass
)

Perform static checking to determine whether the given method matches.

public boolean

Returns:

whether there's a runtime match
matches
(Method
the candidate method
method
,
Class<?>
the target class
targetClass
,
Object...
arguments to the method
args
)

Check whether there is a runtime (dynamic) match for this method, which must have matched statically.

Field Detail

TRUEback to summary
public static final MethodMatcher TRUE

Canonical instance of a MethodMatcher that matches all methods.

Method Detail

isRuntimeback to summary
public boolean isRuntime()

Is this MethodMatcher dynamic, that is, must a final check be made via the matches(Method, Class, Object[]) method at runtime even if matches(Method, Class) returns true?

Can be invoked when an AOP proxy is created, and need not be invoked again before each method invocation.

Returns:boolean

whether a runtime match via matches(Method, Class, Object[]) is required if static matching passed

matchesback to summary
public boolean matches(Method method, Class<?> targetClass)

Perform static checking to determine whether the given method matches.

If this method returns false or if isRuntime() returns false, no runtime check (i.e. no matches(Method, Class, Object[]) call) will be made.

Parameters
method:Method

the candidate method

targetClass:Class<?>

the target class

Returns:boolean

whether this method matches statically

matchesback to summary
public boolean matches(Method method, Class<?> targetClass, Object... args)

Check whether there is a runtime (dynamic) match for this method, which must have matched statically.

This method is invoked only if matches(Method, Class) returns true for the given method and target class, and if isRuntime() returns true.

Invoked immediately before potential running of the advice, after any advice earlier in the advice chain has run.

Parameters
method:Method

the candidate method

targetClass:Class<?>

the target class

args:Object[]

arguments to the method

Returns:boolean

whether there's a runtime match

See Also
matches(Method, Class)