CHAPTER 5: Building Java Web Applications with Spring Web MVC 241
Listing 5-36. The Web Deployment Description for Spring MVC
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" - version="3.0">
contextConfigLocation
/WEB-INF/spring/root-context.xml
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/spring/appServlet/servlet-context.xml
1
appServlet
/
Lines 2 to 4: In the <web-app> tag, the version attribute and the corresponding
URL are changed to version 3.0 to indicate to the web container that the web
application will use Servlet 3.0.
Lines 7 to 10: In the <context-param> tag, the contextConfigLocation param
is provided, which defines the location of Spring’s root WebApplicationContext
configuration file.
Lines 13 to 15: A listener of class org.springframework.web.context.
ContextLoaderListener is defined. This is for Spring to load the root
WebApplicationContext.
Lines 18 to 26: One dispatcher servlet (called appServlet) is defined. We use the
one generated by the template project for the application’s presentation layer.
The WebApplicationContext for the dispatcher servlet is located at
/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml.