Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between a Handler, a Resolver and an Interceptor in Spring MVC?

A Handler, a Resolver and an Interceptor in Spring MVC all seem to do something similar - namely provide the ability to pre-process a request before it reaches the Controller?

What distinguishes these three?

like image 577
Loop Avatar asked Jun 25 '11 14:06

Loop


1 Answers

They aren't the same and also to my knowledge the resolvers aren't really playing a part in pre-processing the request. Interceptors fire before the handlers. From Spring MVC docs:

Interceptor:

Spring's handler mapping mechanism has the notion of handler interceptors, that can be extremely useful when you want to apply specific functionality to certain requests, for example, checking for a principal. Interceptors located in the handler mapping must implement HandlerInterceptor from the org.springframework.web.servlet package. This interface defines three methods, one that will be called before the actual handler will be executed, one that will be called after the handler is executed, and one that is called after the complete request has finished. These three methods should provide enough flexibility to do all kinds of pre- and post-processing.

Handler:

a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files. The default handler is based on the @Controller and @RequestMapping annotations, offering a wide range of flexible handling methods.

Resolver(s):

  • View resolvers: View resolvers are components capable of resolving view names to views
  • Locale resolver: A locale resolver is a component capable of resolving the locale a client is using, in order to be able to offer internationalized views
  • Theme resolver: A theme resolver is capable of resolving themes your web application can use, for example, to offer personalized layouts
  • Multipart file resolver: A multipart file resolver offers the functionality to process file uploads from HTML forms
  • Handler exception resolver(s): Handler exception resolvers offer functionality to map exceptions to views or implement other more complex exception handling code
like image 124
abalogh Avatar answered Oct 11 '22 13:10

abalogh