We need to add the application context configuration file to the jboss-springmvc
web application class-path. Add a <listener/>
tag for the org.springframework.web.context.ContextLoaderListener
class, which starts up Spring's WebApplicationContext
root. Specify the config
location for the root context with the contextConfigLocation
context parameter. The org.springframework.web.servlet.DispatcherServlet
servlet dispatches requests to the handler. Specify the init
parameter, contextConfigLocation
, to configure another application context for the Spring MVC application in /WEB-INF/jboss-as-spring-mvc-context.xml
, which is discussed in a later section. Specify a servlet mapping the URL pattern for the DispatcherServlet
servlet. The web.xml
file is listed in the following code:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="..." version="3.1"> <display-name>Java EE 7 Starter Application</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/META-INF/spring/applicationContext.xml, classpath:/META-INF/spring/infrastructure.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>jboss-spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/jboss-as-spring-mvc-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jboss-spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>