Obtenir des paramètres annotés à l'intérieur d'un pointcut
J'ai deux annotation @LookAtThisMethod
et @LookAtThisParameter
si j'ai une coupe transverse (pointcut) autour de l'méthodes avec @LookAtThisMethod
comment ai-je pu extraire les paramètres de ladite méthode qui sont annotés avec @LookAtThisParameter
?
Par exemple:
@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?
}
}
source d'informationauteur soldier.moth
Vous devez vous connecter pour publier un commentaire.
J'ai modélisé ma solution autour de cette autre réponse à une autre question similaire.
La raison que j'ai eu à passer par la classe cible est parce que la classe qui a été annoté est une implémentation d'une interface et ainsi
signature.getMethod().getParameterAnnotations()
retourné null.Ce code couvre les cas où la Méthode appartient à l'interface