Mark
Mark

Reputation: 847

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 something 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.

Upvotes: 1

Views: 1638

Answers (1)

ramnivas
ramnivas

Reputation: 1284

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) {
 ...
}

Upvotes: 2

Related Questions