Spring 通知中的多个带注释的参数值
如何在我的建议中获得注释参数的值。我有一个如下的场景:Spring 通知中的多个带注释的参数值,spring,aspectj,spring-aop,Spring,Aspectj,Spring Aop,如何在我的建议中获得注释参数的值。我有一个如下的场景: @Custom public void xxxx(@Param("a1") Object a, @Param("a2") Object b) { //TODO } 我希望为所有具有@Custom注释的方法定义切入点,这里没有什么特别之处。问题是我想在advice中获取标有@Param的参数和注释本身的值。此类注释参数的数量不是固定的,可以有任意数量,也可以没有 到目前为止,我已经使用了反射,并且我能够获取标记为注释的参数,但不能获
@Custom
public void xxxx(@Param("a1") Object a, @Param("a2") Object b)
{
//TODO
}
我希望为所有具有@Custom注释的方法定义切入点,这里没有什么特别之处。问题是我想在advice中获取标有@Param的参数和注释本身的值。此类注释参数的数量不是固定的,可以有任意数量,也可以没有
到目前为止,我已经使用了反射,并且我能够获取标记为注释的参数,但不能获取注释的值。这就是我获取注释值的方式: 我的注释是@Name:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
@interface Name {
String value();
}
还有一些代码负责获取它:
Annotation[][] parametersAnnotations = method.getParameterAnnotations();
for (int i = 0; i < parametersAnnotations.length; i++) {
Annotation[] parameterAnnotations = parametersAnnotations[i];
Annotation nameAnnotation = null;
for (Annotation annotation : parameterAnnotations) {
if (annotation.annotationType().equals(Name.class)) {
nameAnnotation = annotation;
break;
}
}
if (nameAnnotation != null) {
String textInAnnotation = ((Name)nameAnnotation).value();
}
}
Annotation[]parametersAnnotations=method.getParameterAnnotations();
对于(int i=0;i
我将试一试。谢谢