[英]AspectJ - Get value of annotated method parameter
I created custom annotation @MyAnn
. 我创建了自定义注释
@MyAnn
。 And I will annotate method parameters with it. 我将使用它来注释方法参数。
For example: public static call(@MyAnn String name){...}
例如:
public static call(@MyAnn String name){...}
Using AspectJ, how can I access and update the values of all parameters annotated with the annotation? 使用AspectJ,如何访问和更新使用注释注释的所有参数的值?
I found some sample code showing how to create pointcuts targeting custom annotations, here . 我发现展示了如何创建切入点瞄准定制标注,一些示例代码在这里 。
So for now, I created an aspect with a pointcut. 所以现在,我用切入点创建了一个方面。 But I don't know hot to get value of parameter annotated with
MyAnn
. 但我不知道获得
MyAnn
注释参数值的MyAnn
。
@Aspect
public class MyAnnAspect {
@Around("execution(@my.package.test.MyAnn") // I hope this pointcut will work
public void changeParameter(final ProceedingJoinPoint pjp) throws Throwable {
// How I can there get parameter value (and chage it)?
}
}
I don't think that pointcut work, because it is not the method which is annotated, by the way you can do: 我不认为切入点工作,因为它不是通过您可以做的方式注释的方法:
MethodSignature ms = (MethodSignature) pjp.getSignature();
Method m = ms.getMethod();
Annotation[][] pa = m.getParameterAnnotations();
Now you can iterate over the annotations, and find the proper annotation, if present get the parameter value by calling pjp.getArgs()
. 现在,您可以迭代注释,并找到正确的注释,如果存在,则通过调用
pjp.getArgs()
获取参数值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.