带注释的参数的Spring AOP切入点 [英] Spring AOP pointcut for annotated argument
本文介绍了带注释的参数的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.
这篇关于带注释的参数的Spring AOP切入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文