访问通知中的注释值 [英] Accessing Annotation-value in advice
本文介绍了访问通知中的注释值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我有这样注释的方法:
In my application I have methods annotated like this:
@SomeAnnotation(key1="value1", key2 ="value2")
public void myMethod()
我定义了以下 apsect 来执行这些方法的执行操作:
I have defined the following apsect to perform some action on executing of those methods:
@Aspect
public class MyAspect()
{
@Around("@annotation(my.package.SomeAnnotation)")
public Object doSomething(final ProceedingJoinPoint pjp) throws Throwable
{
...
}
}
现在我想在我的建议中使用注释值(上面例子中的value1"和value2").此时访问注解的方式是什么?
Now I would like to use the annotation values ("value1" and "value2" in the above example) inside my advice. What is the way to access the annotation at this point?
推荐答案
@annotation
可以使用绑定形式,如下:
@annotation
can be used in binding form, as follows:
@Around(value = "@annotation(a)", argNames = "a")
public Object doSomething(final ProceedingJoinPoint pjp, SomeAnnotation a)
throws Throwable { ... }
这篇关于访问通知中的注释值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文