Reputation: 1476
Already defined in the web.xml the location for dispatcher servlet as [/WEB-INF/config/dispatcher-servlet.xml] in the context-param, still why it is looking for [/WEB-INF/dispatcher-servlet.xml].
This will work when putiing the dipatcher-servlet at [/WEB-INF/config/dispatcher-servlet.xml] as well as at [/WEB-INF/dispatcher-servlet.xml] then only it is working.
How it is behaving in such a way ? If changing its current location to [/WEB-INF/config/dispatcher-servlet.xml] why it search at this [/WEB-INF/dispatcher-servlet.xml] location also ?
web.xml
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/dispatcher-servlet.xml,
/WEB-INF/config/spring-security.xml,
/WEB-INF/config/database-config.xml
</param-value>
</context-param>
Error:
May 01, 2016 3:55:49 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
2016-05-01 03:55:49 INFO DispatcherServlet:488 - FrameworkServlet 'dispatcher': initialization started
2016-05-01 03:55:49 INFO XmlWebApplicationContext:578 - Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sun May 01 03:55:49 IST 2016]; parent: Root WebApplicationContext
2016-05-01 03:55:49 INFO XmlBeanDefinitionReader:317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
May 01, 2016 3:55:49 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
Upvotes: 1
Views: 1242
Reputation: 55
Case 1:If you don't defined init-param or context-param and servlet name is dispatcher
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
=>When web.xml load then it will load /WEB-INF/dispatcher-servlet.xml by default.You don't need to define it in init-param
Case 2:When you want to change location of dispatcher-servlet.xml =>you need to mention its path in init-param.Because init-param load this xml
Upvotes: 0
Reputation: 2456
You have defined your Dispatcher servlet like this:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
So by default, it will look for the dispatcher servlet file (dispatcher-servlet.xml) in your classpath (Your servlet name appended by '-servlet.xml').
You have defined dispatcher-servlet.xml but you have kept it under the location /WEB-INF/config/. So provide this location for your dispatcher servlet xml file. Following configuration should work for you.
<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/conf/dispatcher-servlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Upvotes: 1