开发者

AspectJ expose annotation value using AspectJ annotations

开发者 https://www.devze.com 2023-01-23 21:50 出处:网络
I\'m using AspectJ annotations instead of writing actual aspect files. I want to expose an annotation value to my advice.

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

精彩评论

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