I want to apply @Around advice to certain methods (from the specific package) that are either:
- annotated with a custom annotation (@Retryable)
- defined in a class that is annotated with a custom annotation (@Retryable)
Method level annotations can override type level annotation (this is similar to @Transactional):
Code:
@Retryable(maxRetries = 3)
public class AdvisedClass {
@Retryable(maxRetries = 1)
public void advisedMethod1() {
...
}
// maxRetries = 3 should apply
public void advisedMethod2() {
...
}
...
}
I'm able to capture both conditions using two separate pointcut expressions (using @annotation and @target respectively) and my advice method is executed correctly:
Code:
@Around(...)
public Object doDataAccessOperation(ProceedingJoinPoint jp, Retryable retryable) throws Throwable {
int maxRetries = retryable.maxRetries();
...
}
However, when I combine both pointcut expressions, annotation variable that is passed to the advice method is null for one scenario. I'm wondering if the proper design is to have two separate @Around advice methods - one that captures type level and the other that captures method level annotations, i.e:
Code:
@Around(...)
public Object doTypeLevel(ProceedingJoinPoint jp, Retryable retryable) throws Throwable {
int maxRetries = retryable.maxRetries();
...
}
@Around(...)
public Object doMetodLevelLevel(ProceedingJoinPoint jp, Retryable retryable) throws Throwable {
int maxRetries = retryable.maxRetries();
...
}
Thanks,
Lukasz