Learn Java for Web Development

(Tina Meador) #1
CHAPTER 5: Building Java Web Applications with Spring Web MVC 241

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=
    "http://www.w3.org/2001/XMLSchema-instance"

  3. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

  4. version="3.0">










  5. contextConfigLocation


  6. /WEB-INF/spring/root-context.xml













  7. org.springframework.web.context.ContextLoaderListener













  8. appServlet


  9. org.springframework.web.servlet.DispatcherServlet





  10. contextConfigLocation


  11. /WEB-INF/spring/appServlet/servlet-context.xml





  12. 1










  13. appServlet


  14. /










   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.
Free download pdf