img
Introducing Spring MVC
In the Spring Framework, the Spring MVC module provides comprehensive support for the MVC
pattern, with support for other features (for example, theming, i18n, validation, type conversion and
formatting, and so on) that ease the implementation of the presentation layer.
In the following sections, we will discuss the main concepts of Spring MVC. Topics include Spring
MVC's WebApplicationContext hierarchy, a typical request-handling life cycle, and configuration.
Spring MVC WebApplicationContext Hierarchy
In Spring MVC, the DispatcherServlet is the central servlet that receives requests and dispatches them
to the appropriate controllers. In a Spring MVC application, there can be any number of
DispatcherServlets for various purposes (for example, handling user interface requests, RESTful-WS
requests, and so on), and each DispatcherServlet has its own WebApplicationContext configuration,
which defines the servlet-level characteristics, such as controllers supporting the servlet, handler
mapping, view resolving, i18n, theming, validation, type conversion and formatting, and so on.
Underneath the servlet-level WebApplicationContext configurations, Spring MVC also maintains a
root WebApplicationContext, which includes the application-level configurations such as backend data
source, security, service and persistence layer configuration, and so on. The root WebApplicationContext
will be available to all servlet-level WebApplicationContext.
Let's look at an example. Let's say in an application we have two DispatcherServlets. One servlet is
to support the user interface (we call it the application servlet), and the other is to provide services in the
form of RESTful-WS to other applications (we call it the RESTful servlet). In Spring MVC, we will define
the configurations for both the root WebApplicationContext and the WebApplicationContext for the two
DispatcherServlets. Figure 17-2 shows the WebApplicationContext hierarchy that will be maintained by
Spring MVC for this scenario.
Figure 17-2. Spring MVC WebApplicationContext hierarchy
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home