Java Reference
In-Depth Information
Listing 5-36. The Web Deployment Description for Spring MVC
1. <?xml version="1.0" encoding="UTF-8"?>
2. <web-app xmlns="
http://java.sun.com/xml/ns/javaee
"
xmlns:xsi=
3. xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
4. version="3.0">
5.
6. <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
7. <context-param>
8. <param-name>contextConfigLocation</param-name>
9. <param-value>/WEB-INF/spring/root-context.xml</param-value>
10. </context-param>
11.
12. <!-- Creates the Spring Container shared by all Servlets and Filters -->
13. <listener>
14. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
15. </listener>
16.
17. <!-- Processes application requests -->
18. <servlet>
19. <servlet-name>appServlet</servlet-name>
20. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
21. <init-param>
22. <param-name>contextConfigLocation</param-name>
23. <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
24. </init-param>
25. <load-on-startup>1</load-on-startup>
26. </servlet>
27.
28. <servlet-mapping>
29. <servlet-name>appServlet</servlet-name>
30. <url-pattern>/</url-pattern>
31. </servlet-mapping>
32.
33. </web-app>
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
.