As you know, web.xml is the root file of any web application, placed in the WEB-INF directory. It has a servlet specification, and contains all the servlet configuration to be bootstrapped. Let's see the required code of the DispatcherServlet configuration in the web application, which is as follows:
<web-app version="3.0" 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 metadata-complete="true"> <servlet> <servlet-name>bankapp</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>bankapp</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
The preceding code is the minimum required code to configure the DispatcherServlet in a Spring web application using XML-based configuration.
There is nothing is special in the web.xml file; typically, it defines only one servlet configuration very similar to the traditional Java web application. But DispatcherServlet loads a file which contains the spring beans configuration for the application. By default, it loads a file named [servletname]-servlet.xml from the WEB-INF directory. In our case, the file name should be bankapp-servlet.xml in the WEB-INF directory.