問題很簡短:是否有一種方式來獲得從apsectj ProceedingJoinPoint的Method對象?從ProceedingJoinPoint獲取java.lang.reflect.Method?
目前我做
Class[] parameterTypes = new Class[joinPoint.getArgs().length];
Object[] args = joinPoint.getArgs();
for(int i=0; i<args.length; i++) {
if(args[i] != null) {
parameterTypes[i] = args[i].getClass();
}
else {
parameterTypes[i] = null;
}
}
String methodName = joinPoint.getSignature().getName();
Method method = joinPoint.getSignature()
.getDeclaringType().getMethod(methodName, parameterTypes);
,但我不認爲這是要走的路...
當在彈簧引導應用使用上述轉換失敗。然後簽名是類型MethodSignatureImpl,它是一個私有的彈簧MethodInvocationProceedingJoinPoint的內部類。 – Heri 2015-06-11 18:03:11
更新上述評論(這是錯誤的):在我的測試中,我輸入了錯誤的MethodSignature類導致一個ClassCastException。正確的類是org.aspectj.lang.reflect.MethodSignature。 – Heri 2015-06-11 21:55:18