开发者

AspectJ expose annotation value using AspectJ annotations

I'm using AspectJ annotations instead of writing actual aspect files. I want to expose an annotation value to my advice.

I currently have this but it it doesn't expose the values inside MyAnnotation

@Before("execution(@MyAnnotation * * (..))")
public void intercept(JoinPoint jp) {
 ...
}

What I was thinking was somethin开发者_C百科g like this:

@Before("execution(@MyAnnotation * * (..)) && @this(MyAnnotation)")
public void intercept(JoinPoint jp, MyAnnotation myAnnotation) {
 ...
}

This clearly has a syntax error but was wondering if I was close. I can't seem to find an example syntax when using AspectJ annotations to do this.


You are using type, when you should be using an identifier. The correct code is:

@Before("execution(@MyAnnotation * * (..)) && @this(myAnnotation)")
public void intercept(JoinPoint jp, MyAnnotation myAnnotation) {
 ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜