I am studying Spring AOP module and I have some doubts about how exactly works the AROUND advice.
Reading the official documentation: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html
I can read this about the AROUND ADVICE:
Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception.
And this is the sequence diagram of the around advice:
So from what I can understand I can define an advice (my custom behavior) that will perform before and after a joint point specified by a pointcut.
So for example I can define an AROUND ADVICE in this way:
@Around(“execution(@example.Cacheable * rewards.service..*.*(..))”)
public Object cache(ProceedingJoinPoint point) throws Throwable {
Object value = cacheStore.get(cacheKey(point));
if (value == null) {
value = point.proceed();
cacheStore.put(cacheKey(point), value);
}
return value;
}
that perform the implemented chaching behavior before and after that a service method is call. Is it right?
The thing that I can't completly understand is how exactly is and how is it used the ProceedingJoinPoint point parameter.
From what I understand it is used to choose if perform or not perform a specific operation but how exactly works?
Another doubt related how correctly use AOP advice is how to respond to the following question:
Which advice do I have to use if I would like to try and catch exceptions?
I think that in this case the answer is to use the After throwing advice because the advice executes when a matched method execution exits by throwing an exception.
But I am not sure about it because from what I understand the advice is executed only if a method throws an exception. Or maybe in this case I have to use the **AROUND ADVICE* ?
Tnx