Spring Book – Chapter 14 – Spring MVC and Spring Web Flow

Why Spring MVC?

With so many MVC based web application frameworks available in the market, why do you need one more MVC-based web application framework?

I will try to answer this question by letting you go through Spring MVC’s brief history and its strength in this section.

To reiterate, Spring Framework was first released in June 2003 and the first release version 1.0 got released in March 2004. At that point in time the number of web application frameworks based on MVC was really very slim. Of the available MVC web application frameworks, Apache Struts led the way in quite a substantial fashion and was without any doubt market leader closely followed by so called WebWork developed by OpenSymphony. Spring Framework wanted to reinvent MVC based web application framework by realizing its own framework in the form of Spring MVC. Taking care of some of the architectural deficiencies and introducing various strengths, Spring MVC came into the market competing with the famous Struts.

Spring MVC boasts lot of benefits/strengths, of which some of them are highlighted as summarized below:

  • Based on Spring Framework and uses all of its features in all aspects
  • Simple, easy to understand and comprehend
  • Highly flexible and extensible
  • Capability to support various view technologies
  • Simple but powerful tag library

Spring MVC Architecture

Spring MVC is a popular request-driven framework and the overall approach is very much similar to the famous Struts web application framework.

Spring MVC closely resembles Apache Struts in many way as you could make out with the side by side basic architecture of both Apache Struts and Spring MVC in Figure 14-2 below.

Apache Struts Vs. Spring MVC

Figure 14-2. Apache Struts Vs. Spring MVC

Spring MVC forms the foundation for all the Spring web modules and comes packaged with the Spring Framework. The Spring MVC’s architecture can be pictorially represented as shown in Figure 14-3 below.

Spring MVC architecture

Figure 14-3. Spring MVC architecture

As shown in Figure 14-1 above, it implements the famous MVC pattern which in turn uses the “Front Controller” software design pattern. The Front Controller in Spring MVC is enacted by “DispatcherServlet”. The events happening when the Front Controller (DispatcherServlet) receives the request from the user can be summarized as below:

  1. The Front Controller (DispatcherServlet) which is configured in the web deployment descriptor (web.xml), receives the request from the client.
  2. With the help from HandlerMapping (explained in later sections), finds the appropriate Controller and invokes it.
  3. The Controller executes the business logic (calls a service in the business tier) and returns a ModelAndView object back to the DispatcherServlet.
  4. The DispatcherServlet now determines the appropriate view from the ModelAndView object.
  5. The DispatcherServlet now passes the model object to the selected View.
  6. The View is now generated and send to the DispatcherServlet, which sends the response back to the Servlet Container, which then sends the response back to the user.

Page Visitors: 6486

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *