Consider I have defined the following aspect:
@Aspect
public class SampleAspect {
@Around(value="@annotation(sample.SampleAnnotation)")
public Object display(ProceedingJoinPoint joinPoint) throws Throwable {
// ...
}
}
and the annotation
public @interface SampleAnnotation {
String value() default "defaultValue";
}
Is there a way to read the value parameter of the annotation SampleAnnotation in the display method if my aspect?
Thanks for your help, erik
Change the advice signature to
and you will have access to the value in the annotation.
See docs for more info.
Bellow I'll add a complete example of AOP implementation where I'll getting parameter from my Custom pointCut annotation, where my advice aim to calculate the time execution of a function:
1- Custom Annotation:
2- Controller:
3- Advice
Explanation:
Our advice (logExecutionTime) will be excuted around (joinPoint) the function that will be annotated with AnnotationLogExecutionTime (our custom annotation) so I want to active or not this the calculation of time execution so I'll get the value from the membre of our custom annotation (which you ask about ;) )