For some reasons, I need to name the XML files for the Spring Context in a way different from the standard.
Yes, I know that this is a basic question and there are several responses to it on Stack Overflow, for example:
- Spring Context Configuration
- Spring MVC Context Hiearchy
- Spring-MVC: What are a "context" and "namespace"?
However, my question is a little bit trickier than those, because the system only runs if the web.xml file has BOTH <init-param> and <context-param> doing THE SAME THING, as showed in the code below:
<!--
TAG A: <init-param>
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/myDearServlet.xml,
/WEB-INF/springSecurityStuff.xml
</param-value>
</init-param>
AND
<!--
TAG B: <context-param>
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/myDearServlet.xml,
/WEB-INF/springSecurityStuff.xml
</param-value>
</context-param>
If I eliminate only the TAG A: <init-param> the system doesn't run and the error is:
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/my-dispatcher-servlet.xml]
(the name of the servlet is "my-dispatcher")
and if I eliminate only the TAG B: <context-param> the system doesn't run either and the error is:
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
If I don't eliminate any of them the system runs normally. Here is the web.xml that works:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd"
version="2.4">
<display-name>Weird Spring MVC</display-name>
<!-- SPRING MVC SERVLET -->
<servlet>
<servlet-name>my-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--
TAG A: <init-param>
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/myDearServlet.xml,
/WEB-INF/springSecurityStuff.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>my-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
TAG B: <context-param>
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/myDearServlet.xml,
/WEB-INF/springSecurityStuff.xml
</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Does anyone have a simple(?) explanation for this behavior?
Thanks in advance.
Almir Campos.