假设我有这样的方法:
public void method(@CustomAnnotation("value") String argument)
是否有一个切入点表达式可以选择所有带有 @CustomAnnotation 注释的参数的方法?如果是这样,有没有办法让我访问“值(value)”参数?
最佳答案
关于选择你的论点:
@Before("execution(* *(@CustomAnnotation (*)))")
public void advice() {
System.out.println("hello");
}
引用:http://forum.springsource.org/archive/index.php/t-61308.html
在获取注释参数时:
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
Annotation[][] methodAnnotations = method.getParameterAnnotations();
将为您提供可以迭代的注释并使用 instanceof 来查找绑定(bind)的注释。我知道那很hacky,但afaik这是目前唯一支持的方式。
关于注释参数的 Spring AOP 切入点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10247116/