Spring MVC Framework

The Spring Web MVC framework provides Model-View-Controller (MVC) architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.

  • The Model encapsulates the application data and in general they will consist of POJO.
  • The View is responsible for rendering the model data and in general it generates HTML output that the client’s browser can interpret.
  • The Controller is responsible for processing user requests and building an appropriate model and passes it to the view for rendering.

The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that handles all the HTTP requests and responses. The request processing workflow of the Spring Web MVC DispatcherServlet is illustrated in the following diagram −

A spring controller is a simple Java class. This class is annotated with @Controller on the class level. The controller and/or its methods are mapped to request URI using @RequestMapping. The controller’s methods are usually known as handlers. There can be multiple controller classes in an application. A controller is registered as a bean. That means we can inject any other bean/service there. The default scope of a controller is singleton.

org.springframework.ui.Model serves as MVC model. It binds the view attributes with application specific values. If the handler method parameters list has Model type, its instance is passed by Spring.


Spring framework comes with many views. One of the commonly used views is JstlView, which expects JSP resources be provided at specified location under webapp directory. That means a developer responsibility is to provide a JSP file. A JSP file uses model’s provided attribute. for example:

What is ViewResolver?

ViewResolver is an interface. Typically, the implementation of this interface is responsible to resolve views by name. We don’t have to implement it ourselves as there are already many view resolvers available. One of the commonly used view resolvers is InternalResourceViewResolver, it's default View is JstlView, which can be changed. We can configure multiple view resolver in an application.

we can configure view resolver as a bean:-

In above configuration the Jstl resources must be located under /WEB-INF/views/ directory and must have file extension of jsp.