2
votes

I want to load myapp-servlet.xml as my web application context. I have neither defined spring contextLoaderListner not have defined context params, only the dispatcher servlet is defined.

   <display-name>myapp</display-name>
    <description/>
    <servlet>
        <servlet-name>myapp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>myapp</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

config file is present in /WEB-INF/myapp-servlet.xml and I'm expecting it to be loaded. But I'm getting the following exception

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)

I'm want to know why the default applicationContext.xml file is looked for even when context-param and contextLoaderListener is not defined?

2

2 Answers

0
votes

Just add the appropriate context-param for your Spring config file:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/myapp-servlet.xml</param-value>
</context-param>

There is probably a default config file location in the Spring code... Seems like a good opportunity to UTSL...

0
votes

Just add

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

to your web.xml