Listing 17-8. The root-context.xml File
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<import resource="classpath:datasource-tx-jpa.xml" />
<context:component-scan
base-package="com.apress.prospring3.ch17.service.jpa" />
</beans>
First the context namespace is added to the configuration file. Then the file datasource-tx-jpa.xml
is imported into the WebApplicationContext, and finally, we instruct Spring to scan for the specified
package for Spring beans.
Now the service layer is completed and ready to be exposed and used by remote clients.
Introducing MVC and Spring MVC
Before we move on to implement the presentation layer, let's go through some major concepts of MVC
as a pattern in web applications and how Spring MVC provides comprehensive support in this area.
In the following sections, we will discuss these high-level concepts one by one. First, we will give a
brief introduction to MVC. Second, we will present a high-level view of Spring MVC and its
WebApplicationContext hierarchy. Finally, we will discuss the request life cycle within Spring MVC.
Introducing MVC
MVC is a commonly used pattern in implementing the presentation layer of an application. The main
principle of the MVC pattern is to define an architecture with clear responsibilities for different
components. As its name implies, there are three participants within the MVC pattern:
Model: A model represents the business data as well as the "state" of the
·
application within the context of the user. For example, in an e-commerce web
site, the model will include the user profile information, shopping cart data, and
order data if users purchase goods on the site.
View: This presents the data to the user in the desired format, supports interaction
·
with users, and supports client-side validation, i18n, styles, and so on.
Controller: The controller handles requests for actions performed by users in the
·
frontend, interacting with the service layer, updating the model, and directing
users to the appropriate view based on the result of execution.
Because of the rise of Ajax-based web applications, the MVC pattern has been enhanced to provide
a more responsive and rich user experience. For example, when using JavaScript, the view can "listen" to
events or actions performed by the user and then submit an XMLHttpRequest to the server. On the
controller side, instead of returning the view, the raw data (for example, in XML or JSON format) is
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home