What are Interceptors?

Interceptor are the classes that extends either HandlerInterceptor or implements HandlerInterceptor interface.

HandlerInterceptor has 3 methods:

  • boolean prehandle(): called just before the handler method. Return type of this method is boolean,it tells to process request further (on true) or not (on false).
  • void posthandle(): called just after the handler method is executed.
  • void afterCompletion(): called immediately after view is generated.

How Interceptors work ?

spring-interceptors.png