在访问通知注解价值 [英] 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
{
...
}
}
现在我想用注释的值(在上面的例子值1和值2),我的建议里。什么是在这一点上访问注解的方式是什么?
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屋!
查看全文