Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value of an annotation parameter for usage in AspectJ?

Consider this method:

@Access(rights = GUEST)
public void foo() {
  doSomething();
}

This pointcut basically matches if the method has an @Access annotation:

pointcut check() : 
execution(@Access * *(..));

But how can I access the field rights of @Access, which stores the particular access level, so that I can work with it?

like image 221
soc Avatar asked Jul 20 '11 12:07

soc


People also ask

Which annotation in AspectJ helps us to identify aspects?

The @Aspect annotation on a class marks it as an aspect, and hence excludes it from auto-proxying.

What is pointcut and JoinPoint in Spring?

Pointcut: Pointcut is expressions that are matched with join points to determine whether advice needs to be executed or not. Pointcut uses different kinds of expressions that are matched with the join points and Spring framework uses the AspectJ pointcut expression language.

What is pointcut in AOP?

Pointcut is a set of one or more JoinPoint where an advice should be executed. You can specify Pointcuts using expressions or patterns as we will see in our AOP examples. In Spring, Pointcut helps to use specific JoinPoints to apply the advice.

What is advice in AspectJ?

AspectJ supports three kinds of advice. The kind of advice determines how it interacts with the join points it is defined over. Thus AspectJ divides advice into that which runs before its join points, that which runs after its join points, and that which runs in place of (or "around") its join points.


1 Answers

Try to use:

pointcut check(Access access) : 
execution(@Access * *(..)) && @annotation(access);

See documentation here.

like image 104
Constantiner Avatar answered Nov 14 '22 23:11

Constantiner