Here is my MethodLogger aspect that I will create:
You can see that I do some DI via annotations:
A normal constructor with one optional argument for logging results:
And our invokeMethod implementation:
As you can see, the before advice part is what happens before the execution of the real method (or more aspects) occurrs. So everything before the call to arguments.invocation.proceed()
:
Then we execute the real method or more aspects (we do not do anything around the method call):
Finally, we do the after advice part which happens after the method or other aspects fire and results are returned:
That's it. I have succesfully created an aspect. What's next!