Top Description Inners Constructors Methods
org.springframework.aop.support

public abstract Class AopUtils

extends Object
Class Inheritance
Imports
java.lang.reflect.InvocationTargetException, .Method, .Modifier, .Proxy, java.util.ArrayList, .LinkedHashSet, .List, .Set, kotlin.coroutines.Continuation, kotlin.coroutines.CoroutineContext, kotlinx.coroutines.Job, org.reactivestreams.Publisher, org.springframework.aop.Advisor, .AopInvocationException, .IntroductionAdvisor, .IntroductionAwareMethodMatcher, .MethodMatcher, .Pointcut, .PointcutAdvisor, .SpringProxy, .TargetClassAware, org.springframework.core.BridgeMethodResolver, .CoroutinesUtils, .KotlinDetector, .MethodIntrospector, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ReflectionUtils

Utility methods for AOP support code.

Mainly for internal use within Spring's AOP support.

See org.springframework.aop.framework.AopProxyUtils for a collection of framework-specific AOP utility methods which depend on internals of Spring's AOP framework implementation.

Authors
Rod Johnson, Juergen Hoeller, Rob Harrop, Sebastien Deleuze
See Also
org.springframework.aop.framework.AopProxyUtils

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
AopUtils.KotlinDelegate

Inner class to avoid a hard dependency on Kotlin at runtime.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

whether the pointcut can apply on any method
canApply
(Pointcut
the static or dynamic pointcut to check
pc
,
Class<?>
the class to test
targetClass
)

Can the given pointcut apply at all on the given class?

public static boolean

Returns:

whether the pointcut can apply on any method
canApply
(Pointcut
the static or dynamic pointcut to check
pc
,
Class<?>
the class to test
targetClass
,
boolean
whether the advisor chain for this bean includes any introductions
hasIntroductions
)

Can the given pointcut apply at all on the given class?

public static boolean

Returns:

whether the pointcut can apply on any method
canApply
(Advisor
the advisor to check
advisor
,
Class<?>
class we're testing
targetClass
)

Can the given advisor apply at all on the given class?

public static boolean

Returns:

whether the pointcut can apply on any method
canApply
(Advisor
the advisor to check
advisor
,
Class<?>
class we're testing
targetClass
,
boolean
whether the advisor chain for this bean includes any introductions
hasIntroductions
)

Can the given advisor apply at all on the given class?

public static List<Advisor>

Returns:

sublist of Advisors that can apply to an object of the given class (may be the incoming List as-is)
findAdvisorsThatCanApply
(List<Advisor>
the Advisors to evaluate
candidateAdvisors
,
Class<?>
the target class
clazz
)

Determine the sublist of the candidateAdvisors list that is applicable to the given class.

public static Method

Returns:

the specific target method, or the original method if the targetClass doesn't implement it or is null
getMostSpecificMethod
(Method
the method to be invoked, which may come from an interface
method
,
Class<?>
the target class for the current invocation. May be null or may not even implement the method.
targetClass
)

Given a method, which may come from an interface, and a target class used in the current AOP invocation, find the corresponding target method if there is one.

public static Class<?>

Returns:

the target class (or the plain class of the given object as fallback; never null)
getTargetClass
(Object
the instance to check (might be an AOP proxy)
candidate
)

Determine the target class of the given bean instance which might be an AOP proxy.

public static Object

Returns:

the invocation result, if any
invokeJoinpointUsingReflection
(Object
the target object
target
,
Method
the method to invoke
method
,
Object[]
the arguments for the method
args
)

Invoke the given target via reflection, as part of an AOP method invocation.

public static boolean
isAopProxy(Object
the object to check
object
)

Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.

public static boolean
isCglibProxy(Object
the object to check
object
)

Check whether the given object is a CGLIB proxy.

public static boolean
isEqualsMethod(Method method)

Determine whether the given method is an "equals" method.

public static boolean
isFinalizeMethod(Method method)

Determine whether the given method is a "finalize" method.

public static boolean
isHashCodeMethod(Method method)

Determine whether the given method is a "hashCode" method.

public static boolean
isJdkDynamicProxy(Object
the object to check
object
)

Check whether the given object is a JDK dynamic proxy.

public static boolean
isToStringMethod(Method method)

Determine whether the given method is a "toString" method.

public static Method

Returns:

a corresponding invocable method on the target type
selectInvocableMethod
(Method
the method to check
method
,
Class<?>
the target type to search methods on (typically an AOP proxy)
targetType
)

Select an invocable method on the target type: either the given method itself if actually exposed on the target type, or otherwise a corresponding method on one of the target type's interfaces or on the target type itself.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AopUtilsback to summary
public AopUtils()

Method Detail

canApplyback to summary
public static boolean canApply(Pointcut pc, Class<?> targetClass)

Can the given pointcut apply at all on the given class?

This is an important test as it can be used to optimize out a pointcut for a class.

Parameters
pc:Pointcut

the static or dynamic pointcut to check

targetClass:Class<?>

the class to test

Returns:boolean

whether the pointcut can apply on any method

canApplyback to summary
public static boolean canApply(Pointcut pc, Class<?> targetClass, boolean hasIntroductions)

Can the given pointcut apply at all on the given class?

This is an important test as it can be used to optimize out a pointcut for a class.

Parameters
pc:Pointcut

the static or dynamic pointcut to check

targetClass:Class<?>

the class to test

hasIntroductions:boolean

whether the advisor chain for this bean includes any introductions

Returns:boolean

whether the pointcut can apply on any method

canApplyback to summary
public static boolean canApply(Advisor advisor, Class<?> targetClass)

Can the given advisor apply at all on the given class? This is an important test as it can be used to optimize out an advisor for a class.

Parameters
advisor:Advisor

the advisor to check

targetClass:Class<?>

class we're testing

Returns:boolean

whether the pointcut can apply on any method

canApplyback to summary
public static boolean canApply(Advisor advisor, Class<?> targetClass, boolean hasIntroductions)

Can the given advisor apply at all on the given class?

This is an important test as it can be used to optimize out an advisor for a class. This version also takes into account introductions (for IntroductionAwareMethodMatchers).

Parameters
advisor:Advisor

the advisor to check

targetClass:Class<?>

class we're testing

hasIntroductions:boolean

whether the advisor chain for this bean includes any introductions

Returns:boolean

whether the pointcut can apply on any method

findAdvisorsThatCanApplyback to summary
public static List<Advisor> findAdvisorsThatCanApply(List<Advisor> candidateAdvisors, Class<?> clazz)

Determine the sublist of the candidateAdvisors list that is applicable to the given class.

Parameters
candidateAdvisors:List<Advisor>

the Advisors to evaluate

clazz:Class<?>

the target class

Returns:List<Advisor>

sublist of Advisors that can apply to an object of the given class (may be the incoming List as-is)

getMostSpecificMethodback to summary
public static Method getMostSpecificMethod(Method method, Class<?> targetClass)

Given a method, which may come from an interface, and a target class used in the current AOP invocation, find the corresponding target method if there is one. E.g. the method may be IFoo.bar() and the target class may be DefaultFoo. In this case, the method may be DefaultFoo.bar(). This enables attributes on that method to be found.

Note

In contrast to org.springframework.util.ClassUtils#getMostSpecificMethod, this method resolves bridge methods in order to retrieve attributes from the original method definition.

Parameters
method:Method

the method to be invoked, which may come from an interface

targetClass:Class<?>

the target class for the current invocation. May be null or may not even implement the method.

Returns:Method

the specific target method, or the original method if the targetClass doesn't implement it or is null

See Also
org.springframework.util.ClassUtils#getMostSpecificMethod, org.springframework.core.BridgeMethodResolver#getMostSpecificMethod
getTargetClassback to summary
public static Class<?> getTargetClass(Object candidate)

Determine the target class of the given bean instance which might be an AOP proxy.

Returns the target class for an AOP proxy or the plain class otherwise.

Parameters
candidate:Object

the instance to check (might be an AOP proxy)

Returns:Class<?>

the target class (or the plain class of the given object as fallback; never null)

See Also
org.springframework.aop.TargetClassAware#getTargetClass(), org.springframework.aop.framework.AopProxyUtils#ultimateTargetClass(Object)
invokeJoinpointUsingReflectionback to summary
public static Object invokeJoinpointUsingReflection(Object target, Method method, Object[] args) throws Throwable

Invoke the given target via reflection, as part of an AOP method invocation.

Parameters
target:Object

the target object

method:Method

the method to invoke

args:Object[]

the arguments for the method

Returns:Object

the invocation result, if any

Annotations
@Nullable
Exceptions
Throwable:
if thrown by the target method
AopInvocationException:
in case of a reflection error
isAopProxyback to summary
public static boolean isAopProxy(Object object)

Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.

This method additionally checks if the given object is an instance of SpringProxy.

Parameters
object:Object

the object to check

See Also
isJdkDynamicProxy, isCglibProxy
isCglibProxyback to summary
public static boolean isCglibProxy(Object object)

Check whether the given object is a CGLIB proxy.

This method goes beyond the implementation of ClassUtils#isCglibProxy(Object) by additionally checking if the given object is an instance of SpringProxy.

Parameters
object:Object

the object to check

See Also
ClassUtils#isCglibProxy(Object)
isEqualsMethodback to summary
public static boolean isEqualsMethod(Method method)

Determine whether the given method is an "equals" method.

See Also
java.lang.Object#equals
isFinalizeMethodback to summary
public static boolean isFinalizeMethod(Method method)

Determine whether the given method is a "finalize" method.

See Also
java.lang.Object#finalize()
isHashCodeMethodback to summary
public static boolean isHashCodeMethod(Method method)

Determine whether the given method is a "hashCode" method.

See Also
java.lang.Object#hashCode
isJdkDynamicProxyback to summary
public static boolean isJdkDynamicProxy(Object object)

Check whether the given object is a JDK dynamic proxy.

This method goes beyond the implementation of Proxy#isProxyClass(Class) by additionally checking if the given object is an instance of SpringProxy.

Parameters
object:Object

the object to check

See Also
java.lang.reflect.Proxy#isProxyClass
isToStringMethodback to summary
public static boolean isToStringMethod(Method method)

Determine whether the given method is a "toString" method.

See Also
java.lang.Object#toString()
selectInvocableMethodback to summary
public static Method selectInvocableMethod(Method method, Class<?> targetType)

Select an invocable method on the target type: either the given method itself if actually exposed on the target type, or otherwise a corresponding method on one of the target type's interfaces or on the target type itself.

Parameters
method:Method

the method to check

targetType:Class<?>

the target type to search methods on (typically an AOP proxy)

Returns:Method

a corresponding invocable method on the target type

Exceptions
IllegalStateException:
if the given method is not invocable on the given target type (typically due to a proxy mismatch)
Since
4.3
See Also
MethodIntrospector#selectInvocableMethod(Method, Class)
org.springframework.aop.support back to summary

private Class AopUtils.KotlinDelegate

extends Object
Class Inheritance

Inner class to avoid a hard dependency on Kotlin at runtime.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Publisher<?>
invokeSuspendingFunction(Method method, Object target, Object... args)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

KotlinDelegateback to summary
private KotlinDelegate()

Method Detail

invokeSuspendingFunctionback to summary
public static Publisher<?> invokeSuspendingFunction(Method method, Object target, Object... args)