DanielBK
DanielBK

Reputation: 942

Spring AOP: In an Around advice, can I call proceed() multiple times?

I am reading through some Spring AOP course and I have just a short question: What would happen if inside of an @Around advice I would do multiple calls to proceed() on the ProceedingJoinPoint? There would simply be multiple method invocations? Unfortunately, I have no possibility to test it right now.

Upvotes: 2

Views: 933

Answers (1)

Filippo Possenti
Filippo Possenti

Reputation: 1410

As the objective of AOP is to wrap additional logic around your own in order to achieve arbitrary goals, theoretically it should be possible to do what you ask and I do believe there may even be legitimate uses for it (like automatically wiring logic to do multiple attempts on "best effort" services).

You will however have to be very careful in setting up such a mechanism as you may end up calling multiple times methods that ARE NOT meant to be called multiple times. Make sure your Pointcut is VERY strict.

Upvotes: 3

Related Questions