I'm not too familiar with the pointpointJ AspectJ syntax, but is there any way to exclude the getTotalBalance call from the pointcut definition? This will prevent recursion from recurring.
Also, your pointcut definition seems to fit too tightly: I believe that the balance check you implement in your aspect should only be done for writing methods. Thus, a call in readonly mode, such as getTotalBalance , should not match. You have a way to distinguish between readonly and write methods in the target class, e. d. existing transaction annotations or something like that?
If not, you can enter these (custom) annotations yourself and configure your pointcut to match all calls to public methods that are not marked readonly. But this will mean changing the code in the target class, which is not always an option. But YMMV.
source share