The architecture and components of Spring MVC

Having gone through your first Spring MVC application, it is now time to look at Spring MVC applications from an architectural perspective:

The architecture and components of Spring MVC

Spring MVC components

As the name implies, Spring MVC follows the renowned MVC architectural pattern. This pattern ensures the separation of concerns by dividing responsibilities into three major roles:

  • Model: This represents data and business logic
  • View: This represents presentation
  • Controller: This processes client requests and delegates them to the view for rendering back to the client

The Model we are talking about here is not necessarily persistent data (a data model) as such; rather, it represents the information passed back and forth between the client and different layers of the server application, which form the building blocks of any system.

Besides the Model, View, and Controller components, DispatcherServlet too plays a crucial role in the Spring MVC architecture. It acts as the Front Controller, a popular J2EE design pattern adopted by many MVC Frameworks. In fact, DispatcherServlet does much more than just a Front Controller. It will be explained in detail in the next section.

In a Spring MVC application, DispatcherServlet first receives a client request hitting the server via HTTP with a URL. With the help of the HandlerMapping configuration, DipatcherServlet finds the appropriate Controller method for the request based on the URL pattern and delegates the request to it. The Controller processes the request, optionally fills in the Model object, and returns the name of the View to be rendered. DispatcherServlet then picks the View up and renders it back on the client after applying the attributes of the Model to the placeholders in the View.

What's mentioned in the previous paragraph is simply the typical request processing flow of Spring MVC. However, it is extremely flexible, with a great many options to support different types of view technologies and input and output structures and formats, including files, streams, and so on. We will explore them more in the following sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset