Study On The Spring Framework Computer Science Essay

Published: Last Edited:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

A web application framework is a software framework that is designed to support the development of dynamic websites, Web applications, and Web services. The framework aims to alleviate the overhead associated with common activities performed in Web development. For example, many frameworks provide libraries for database access, templating frameworks, and session management, and they often promote the reuse of code. Many frameworks follow the Model View Controller (MVC) architectural pattern to separate the data model with business rules from user interface. This is generally considered a good practice as it modularizes code, promotes code reuse, and allows multiple interfaces to be applied. Most MVC frameworks follow a push-based architecture. These frameworks use actions that do the required processing, and then push the data to the view layer to render the results. The Spring framework is a good example of this architecture. This paper will look at how Spring Framework implements the MVC model and how the Spring Framework handles its MVC layers. The main features of Spring MVC will also be discussed.

The Spring Framework

In the world of networked applications, web applications are very much in demand. Due to this demand, every language is providing frameworks that try to make web-application development simpler. The simplicity is not provided just through setting up the basic application structure or generating code. These frameworks are trying to provide simplicity through plug-ability of the frameworks so the components of different frameworks can be brought together without much difficulty.

Among such frameworks, Spring Framework is one of the most used. With its support to multiple Data Access frameworks/libraries it is suitable for scenarios where one would like mix-and-match multiple frameworks, a different one for each layer. This aspect of Spring Framework becomes more suitable for development of web-applications where the UI does not need to know with which framework it is dealing with for business process or data access. The component of the Spring Framework stack that caters to the web UI is Spring MVC.

Spring is a Java-based framework with a focus on web applications and enterprise applications. It is one of the most popular in the Java space. Spring's Web MVC framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for upload files. Spring Web MVC allows you to use any object as a command or form object - there is no need to implement a framework-specific interface or base class. Spring's data binding is highly flexible: for example, it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. (Hoeller, 2010)

How Spring Framework implements the MVC model

Spring MVC is a framework based on Model (M), View (V), Controller (C) pattern. Currently there are several well known web-application frameworks that implement the MVC pattern. The features of Spring MVC that set it apart from other frameworks are the pluggable view technology and the injection of services into controllers. Various view technologies are available in the market (including Tiles, Velocity, etc) with which Spring MVC can quite easily be integrated. In other words, JSP (JavaServer Pages) is not the only template engine supported.

Pluggable view technology

The pluggable feature is not limited to the templating technologies. By using common configuration functionality, other frameworks such as JSF (JavaServer Faces) can be integrated with Spring MVC applications. It is possible to mix-and-match different view technologies by using Spring MVC. (Rajshekhar, 2009)

Injection of Services into Controllers

This feature comes into picture when the Spring Framework is used to implement the business layer. Using the IoC (Inversion of Control) capabilities of Spring Framework, the business layer services and/or objects can be injected into the controller without explicitly setting up the call to the service or mirroring the business layer objects in controller. This helps in reduction of code duplication between Web UI/process layer and business process layer. (Rajshekhar, 2009)

How the Spring Framework handles its MVC layers

Spring MVC is a request-based framework. The framework defines strategy interfaces for all of the responsibilities which must be handled by a modern request-based framework. The goal of each interface is to be simple and clear so that it is easy for Spring MVC users to write their own implementations. MVC paves the way for cleaner front-end code. All interfaces are tightly coupled to the Servlet API. The Servlet API is a protocol by which a Java class may respond to HTTP requests This coupling makes sure that the features of the Servlet API remain available to developers while offering a high abstraction framework to ease working with the API.

The DispatcherServlet class is the front controller of the framework and is responsible for delegating control to the various interfaces during the execution phases of a HTTP request. Some of the most important interfaces defined by Spring MVC, and their responsibilities, are listed below:

HandlerMapping: selecting objects which handle incoming requests (handlers) based on any attribute or condition internal or external to those requests.

HandlerAdapter: execution of objects which handle incoming requests

Controller: comes between Model and View to manage incoming requests and redirect to proper response. It essentially is like a gate that directs the incoming information. It switches between going into model or view.

View: responsible for returning a response to the client. It is possible to go straight to view without going to the model part. It is also possible to go through all three.

The main features of Spring MVC


Model is an object that holds the data to be displayed. It can be any Java object â€" from simple POJO to any type of Collection object. It can also be a combination of both â€" an instance of POJO to hold the detailed data and a collection object to hold all the instances of the POJO which, in reality, is most commonly used Model in Spring MVC. Also, the framework has its own way to hold the data. It holds the data using the Model object that is an instance of org.springframework.ui.ModelMap. Internally, whichever collection class object is used, the framework maps it to the ModelMap class.


In MVC, it is the View that presents the data to the user. Spring MVC, just as many other JEE frameworks, uses a combination of JSP and tag libraries to implement View. Apart from using JSP, many kinds of View technologies like Tiles, Velocity, and Jasper Reports can be plugged into the Framework. The main class behind this plug ability is the org.springframework.web.servlet.View. The View class achieves the plug-in functionality by presenting the View as Logical View instead of actual/physical View. Physical view corresponds to the page developed using any of the templating technologies. The Logical View corresponds to the name of the View to be used. The name is then mapped to the actual View in the configuration file. One important point to remember about how Spring MVC uses Logical View is that Logical View and Model are treated as one entity named Model And View represented by org.springframework.web.servlet.ModelAndView class.


The flow of application and navigation is directed by the controller. It also processes the user input and transforms it into the Model. In Spring MVC, controllers are developed either by extending the out-of-the-box Controller classes or implementing the Controller interface. Following comes under the former category











Of these most commonly used are AbstractController, AbstractCommandController, SimpleFormController and CancellableFormController.


Spring is a powerful framework that solves many common problems in J2EE. Many Spring features are also usable in a wide range of Java environments, beyond classic J2EE.Spring provides a consistent way of managing business objects and encourages good practices such as programming to interfaces, rather than classes. The architectural basis of Spring is an Inversion of Control container based around the use of JavaBean properties. However, this is only part of the overall picture: Spring is unique in that it uses its IoC container as the basic building block in a comprehensive solution that addresses all architectural tiers.