The Spring HandlerInterceptor interface

Spring's request handling mapping mechanism includes the ability to intercept requests by using handler interceptors. These interceptors are used to apply some type of functionality to the requests as in our example of checking whether a user is in session. The interceptors must implement the HandlerInterceptor interface from the org.springframework.web.servlet package where it is possible to apply the functionality in the following three ways:

  • Before the handler method is executed by implementing the preHandle method
  • After the handler method is executed by implementing the postHandle method
  • After the complete request has finished execution by implementing the afterCompletion method

The HandlerInterceptorAdapter ...

Get Enterprise Application Development with Ext JS and Spring now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.