类 AopUtils
Mainly for internal use within AOP support.
- 从以下版本开始:
- 3.0 2021/2/1 18:46
- 作者:
- Rod Johnson, Juergen Hoeller, Rob Harrop, Harry Yang
- 另请参阅:
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static booleanCan the given advisor apply at all on the given class?static booleanCan the given advisor apply at all on the given class?static booleanCan the given pointcut apply at all on the given class?static booleanCan the given pointcut apply at all on the given class?filterAdvisors(List<Advisor> candidateAdvisors, Class<?> clazz) Determine the sublist of thecandidateAdvisorslist that is applicable to the given class.static MethodgetMostSpecificMethod(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.static Class<?>getTargetClass(Object candidate) Determine the target class of the given bean instance which might be an AOP proxy.static Class<?>getTargetClass(MethodInvocation invocation) Determine the target class of the given invocation.static ObjectinvokeJoinpointUsingReflection(Object target, Method method, Object[] args) Invoke the given target via reflection, as part of an AOP method invocation.static booleanisAopProxy(Object object) Check whether the given object is a JDK dynamic proxy or a CGLIB proxy.static booleanisCglibProxy(Object object) Check whether the given object is a CGLIB proxy.static booleanisJdkDynamicProxy(Object object) Check whether the given object is a JDK dynamic proxy.static MethodselectInvocableMethod(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.
-
构造器详细资料
-
AopUtils
public AopUtils()
-
-
方法详细资料
-
isAopProxy
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
StandardProxy.- 参数:
object- the object to check- 另请参阅:
-
isJdkDynamicProxy
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 ofStandardProxy.- 参数:
object- the object to check- 另请参阅:
-
isCglibProxy
Check whether the given object is a CGLIB proxy.- 参数:
object- the object to check
-
getTargetClass
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.
- 参数:
candidate- the instance to check (might be an AOP proxy)- 返回:
- the target class (or the plain class of the given object as fallback;
never
null) - 另请参阅:
-
getTargetClass
Determine the target class of the given invocation.Returns the target class for an AOP proxy or the plain class otherwise.
- 参数:
invocation- the instance to check- 返回:
- the target class (or the plain class of the given object as fallback;
never
null) - 另请参阅:
-
getMostSpecificMethod
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 beIFoo.bar()and the target class may beDefaultFoo. In this case, the method may beDefaultFoo.bar(). This enables attributes on that method to be found.NOTE: In contrast to
ReflectionUtils.getMostSpecificMethod(java.lang.reflect.Method, java.lang.Class<?>), this method resolves bridge methods in order to retrieve attributes from the original method definition.- 参数:
method- the method to be invoked, which may come from an interfacetargetClass- the target class for the current invocation. May benullor may not even implement the method.- 返回:
- the specific target method, or the original method if the
targetClassdoesn't implement it or isnull - 从以下版本开始:
- 4.0
- 另请参阅:
-
ReflectionUtils.getMostSpecificMethod(java.lang.reflect.Method, java.lang.Class<?>)BridgeMethodResolver.getMostSpecificMethod(java.lang.reflect.Method, java.lang.Class<?>)
-
canApply
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.
- 参数:
pc- the static or dynamic pointcut to checktargetClass- the class to test- 返回:
- whether the pointcut can apply on any method
-
canApply
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.
- 参数:
pc- the static or dynamic pointcut to checktargetClass- the class to testhasIntroductions- whether or not the advisor chain for this bean includes any introductions- 返回:
- whether the pointcut can apply on any method
-
canApply
Can the given advisor apply at all on the given class? This is an important test as it can be used to optimize out a advisor for a class.- 参数:
advisor- the advisor to checktargetClass- class we're testing- 返回:
- whether the pointcut can apply on any method
-
canApply
Can the given advisor apply at all on the given class?This is an important test as it can be used to optimize out a advisor for a class. This version also takes into account introductions (for IntroductionAwareMethodMatchers).
- 参数:
advisor- the advisor to checktargetClass- class we're testinghasIntroductions- whether or not the advisor chain for this bean includes any introductions- 返回:
- whether the pointcut can apply on any method
-
filterAdvisors
Determine the sublist of thecandidateAdvisorslist that is applicable to the given class.- 参数:
candidateAdvisors- the Advisors to evaluateclazz- the target class- 返回:
- sublist of Advisors that can apply to an object of the given class (may be the incoming List as-is)
-
invokeJoinpointUsingReflection
public static Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, Object[] args) throws Throwable Invoke the given target via reflection, as part of an AOP method invocation.- 参数:
target- the target objectmethod- the method to invokeargs- the arguments for the method- 返回:
- the invocation result, if any
- 抛出:
Throwable- if thrown by the target methodAopInvocationException- in case of a reflection error
-
selectInvocableMethod
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.- 参数:
method- the method to checktargetType- the target type to search methods on (typically an AOP proxy)- 返回:
- a corresponding invocable method on the target type
- 抛出:
IllegalStateException- if the given method is not invocable on the given target type (typically due to a proxy mismatch)- 从以下版本开始:
- 4.0
- 另请参阅:
-
MethodIntrospector.selectInvocableMethod(Method, Class)
-