AOP 에서 method 가져오기
역시 외국 개발자님들
To whoever is still having problem after** changing annotation retention to Runtime, you might be having the same problem I had: getMethod() returns interface method instead of the implementing class. So, if you have your annotations in the class then naturally getAnnotations() on the interface method returns null.
The following solution solved this problem:
final String methodName = pjp.getSignature().getName(); final MethodSignature methodSignature = (MethodSignature)pjp.getSignature(); Method method = methodSignature.getMethod(); if (method.getDeclaringClass().isInterface()) { method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes()); } and if you like, you have the option of handling interface annotations here too.
Some more comments available here: getting template method instance from ProceedingJoinPoint
Oleg
This article is licensed under CC BY 4.0 by the author.