An advice specifies what must be done at a joinpoint.
Spring uses a chain of interceptors to wrap the invocation of the method and apply to it the advices contained into this chain. As said before, Spring is consistent with the specifications of the AOP Alliance, but provides a slightly different programming model.
The AOP Alliance defines the MethodInterceptor
interface:
public interface org.aopalliance.intercept.MethodInterceptor extends Interceptor { Object invoke(MethodInvocation invocation) throws Throwable; }
By implementing this interface and using the invocation.proceed()
method, it is possible to build a chain of interceptors with the same behavior as filter servlets. In the following figure, we can see this behavior:
Spring, on the other hand, provides prepared advices that extend the org.aopalliance.aop.Advice
interface.
In the following figure, we can see a diagram of the hierarchy of advices:
Advices have been presented with some examples in Chapter 1, but now we will see...