I am new to AOP and I am trying to understand the difference between Method Interceptor and MethodAdvice(i.e. MethodBeforeAdvice or MethodAfterAdvice). To me looks like both are doing the same thing i.e. are called on method invocation. When should we use MethodInterceptor vs MethodAdvice.
Asked
Active
Viewed 2,662 times
1
-
Maybe you should look at this question if you are using spring. [interceptors-vs-aspects-in-spring][1] [1]: http://stackoverflow.com/questions/3599976/interceptors-vs-aspects-in-spring – Seiden Mar 29 '17 at 15:04
1 Answers
4
Take a look at the definition of the org.aopalliance.interceptInterceptor interface (implemented by MethodInterceptor):
public interface Interceptor extends Advice {
}
It's easy to see that a MethodInterceptor actually IS an Advice. The only difference between an Advice being defined in an @Aspect class and such an Interceptor is that Interceptor implementations can be added to and removed from Spring AOP Proxies at runtime (casting them to 'Advised'), whereas the Advice you're talking about is a more static construct. But their still essential to Spring AOP since their presence tells Spring which beans to wrap in a proxy object during application context startup.

pklndnst
- 726
- 2
- 10
- 27