Home  >  Forum  >  Spring
Post New Query

Change dispatcher-servlet.xml file name in Spring



Asked on January 19, 2019
How to change dispatcher-servlet.xml file name in Spring?


Replied on January 19, 2019
Pass contextConfigLocation as init parameter to DispatcherServlet. Suppose you want to change file name as spring-config.xml, you can write web.xml as following.


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
   http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">

<display-name>Spring Demo Project</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/spring-config.xml</param-value>
        </init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app> 


Write Answer








©2019 concretepage.com | Privacy Policy | Contact Us