带注释的参数的Spring AOP切入点

带注释的参数的Spring AOP切入点

问题描述:

说我有一个像这样的方法:

Say I have a method like so:

public void method(@CustomAnnotation("value") String argument)

是否有一个切入点表达式可以选择所有带有@CustomAnnotation注释的参数的方法?如果可以的话,有没有办法我可以访问值"参数?

Is there a pointcut expression that could select all methods with arguments annotated with @CustomAnnotation? If so is there a way I could get access go the "value" argument?

选择参数时:

@Before("execution(* *(@CustomAnnotation (*)))")
public void advice() {
System.out.println("hello");
}

ref: http://forum.springsource.org/archive/index.php/t -61308.html

关于获取注释参数:

MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
Annotation[][] methodAnnotations = method.getParameterAnnotations();

将为您提供批注,您可以对其进行迭代并使用instanceof查找绑定的批注.我知道那很hacky,但是afaik这是目前唯一支持的方式.

Will get you the annotations which you can iterate and use instanceof to find your bound annotation. I know thats hacky but afaik this is the only way supported currently.