Getting the java.lang.reflect.Method from a ProceedingJoinPoint?

前端 未结 2 976
一向
一向 2021-01-31 07:31

The question is short and simple: Is there a way to get the Method object from an apsectj ProceedingJoinPoint?

Currently I am doing

Class[] parameterTy         


        
2条回答
  •  遇见更好的自我
    2021-01-31 07:58

    You should be careful because Method method = signature.getMethod() will return the method of the interface, you should add this to be sure to get the method of the implementation class:

        if (method.getDeclaringClass().isInterface()) {
            try {
                method= jointPoint.getTarget().getClass().getDeclaredMethod(jointPoint.getSignature().getName(),
                        method.getParameterTypes());
            } catch (final SecurityException exception) {
                //...
            } catch (final NoSuchMethodException exception) {
                //...                
            }
        }
    

    (The code in catch is voluntary empty, you better add code to manage the exception)

    With this you'll have the implementation if you want to access method or parameter annotations if this one are not in the interface

提交回复
热议问题