title: My Spring Application could not load the Servlet Context
body: <p>I am working on the Spring4.1.6 release.  I have deployed my Webapplication named SpringMVCTest on Tomcat 7.0. I am getting the below exception on the tomcat startup. Below are the spring configuration file details.</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;web-app 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"
      version="3.0"&gt;
      &lt;display-name&gt;SpringMVC Test Web Application&lt;/display-name&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/config/spring/webmvc-config.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>I have already added the contextConfigLocation parameter inside the web.xml and also below is the contents of the webmvc-config.xml </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans default-autowire="byName"
      xmlns="http://www.springframework.org/schema/beans" 
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xsi:schemaLocation="
           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd 
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd 
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"&gt;
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --&gt;
  
      &lt;!-- Scans within the base package of the application for @Components to configure as beans --&gt;
      &lt;!-- @Controller, @Service, @Configuration, etc. --&gt;
      &lt;context:component-scan base-package="com.springmvc" /&gt;
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Bean class</p>
  
  <pre><code>/**
   * 
   */
  package com.springmvc.bean.Person;
  
  import java.util.List;
  
  /**
   * @author jp48346
   *
   */
  public class Person {
  
      private String name;
      private String email;
      private String gender;
      private String password;
      private String passwordConf;
      private List&lt;String&gt; courses;
      private String tutor;
      private String hiddenMessage;
  
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public String getEmail() {
          return email;
      }
      public void setEmail(String email) {
          this.email = email;
      }
      public String getGender() {
          return gender;
      }
      public void setGender(String gender) {
          this.gender = gender;
      }
      public String getPassword() {
          return password;
      }
      public void setPassword(String password) {
          this.password = password;
      }
      public String getPasswordConf() {
          return passwordConf;
      }
      public void setPasswordConf(String passwordConf) {
          this.passwordConf = passwordConf;
      }
      public List&lt;String&gt; getCourses() {
          return courses;
      }
      public void setCourses(List&lt;String&gt; courses) {
          this.courses = courses;
      }
      public String getTutor() {
          return tutor;
      }
      public void setTutor(String tutor) {
          this.tutor = tutor;
      }
      public String getHiddenMessage() {
          return hiddenMessage;
      }
      public void setHiddenMessage(String hiddenMessage) {
          this.hiddenMessage = hiddenMessage;
      }
  
  }
  </code></pre>
  
  <p>PersonRegistration.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;test Spring MVC Sample&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h2&gt;Fill your form!&lt;/h2&gt;
   &lt;form:form method="POST" commandName="form"&gt;
       &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Enter your name:&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="name" /&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;form:errors path="name" cssStyle="color: #ff0000;"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="submit" name="submit" value="Submit"&gt;&lt;/td&gt;
              &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/form:form&gt;        
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But I don't understand one thing why I am still getting the below exception? As per the logs why it is still trying to look for the applicationContext.xml in the WEB-INF directory? Please help me on this issue and  do let me know if any other information is required to resolve the issue.</p>
  
  <blockquote>
    <p>INFO: Loading XML bean definitions from ServletContext resource
    [/WEB-INF/applicationContext.xml] May 19, 2015 6:36:01 PM
    org.springframework.web.context.ContextLoader
    initWebApplicationContext SEVERE: Context initialization failed
    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:344)
      at
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
      at
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
      at
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
      at
    org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
      at
    org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
      at
    org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
      at
    org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
      at
    org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
      at
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)
      at
    org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
      at
    org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
      at
    org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
      at
    org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
      at
    org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)
      at
    org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at
    org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
      at
    org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
      at java.util.concurrent.FutureTask.run(FutureTask.java:262)     at
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745) Caused by:
    java.io.FileNotFoundException: Could not open ServletContext resource
    [/WEB-INF/applicationContext.xml]     at
    org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
      at
    org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
      ... 21 more</p>
  </blockquote>