@LookAtThisMethod
ve @LookAtThisParameter
iki ek açıklama var, @LookAtThisMethod
ile ilgili yöntemlerin etrafında bir nokta kesme varsa, @LookAtThisParameter
ile açıklamalı olan söz konusu yöntemin parametrelerini nasıl ayırım? ÖrneğinBir nokta işaretinin içinde ek açıklamalı parametreler alın
:
@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?
}
}
Çok teşekkür ederim arayüzüne ait senaryoyu kapsar. Bu cevabı bulmadan çok zaman harcadım. –
Benim için 'signature.getMethod(). GetParameterAnnotations() ', arabirimin yöntemini döndürür ve uygulamayı değil. Yani ek açıklama sadece uygulamada ise, bu çağrı ile null olacaktır. – oleh
'signature.getMethod(). GetAnnotation()' da çalışır. Sadece hatırlatmayı hatırla: '@Retention (RetentionPolicy.RUNTIME) 'olmalıdır. – Kaushik