Spring AOP, when first presented to Java programmers, seemed like magic. How do we have a variable of classX and we call a method on that object? Instead, it executes some aspect before or after the method execution, or even around it, intercepting the call.
The technique that Spring uses is called a dynamic proxy. When we have an object which implements an interface, we can create another object – the proxy object – that also implements that interface, but each and every method implementation invokes a different object called handler, implementing the JDK interface, InvocationHandler. When a method of the interface is invoked on the proxy object, it will call the following method on the handler object:
public Object invoke(Object target, Method m, Object[] args)
This method is free to do anything, even calling the original method on the target...