我有兩個註釋@LookAtThisMethod
和@LookAtThisParameter
,如果我對@LookAtThisMethod
方法有切入點,我怎樣才能提取用@LookAtThisParameter
註解的方法的參數?獲取切入點內的註釋參數
例如:
@Aspect
public class LookAdvisor {
@Pointcut("@annotation(lookAtThisMethod)")
public void lookAtThisMethodPointcut(LookAtThisMethod lookAtThisMethod){}
@Around("lookAtThisMethodPointcut(lookAtThisMethod)")
public void lookAtThisMethod(ProceedingJoinPoint joinPoint, LookAtThisMethod lookAtThisMethod) throws Throwable {
for(Object argument : joinPoint.getArgs()) {
//I can get the parameter values here
}
//I can get the method signature with:
joinPoint.getSignature.toString();
//How do I get which parameters are annotated with @LookAtThisParameter?
}
}
謝謝你這麼多的情況下。在找到這個答案之前,我浪費了很多時間。 –
對我而言,'signature.getMethod()。getParameterAnnotations()'返回接口的方法,而不是實現。所以如果註釋只在實現上,這個調用將會是null。 – oleh
'signature.getMethod()。getAnnotation()'也可以。請記住註釋應該有'@Retention(RetentionPolicy.RUNTIME)'。 – Kaushik