title: Spring application beans being duplicated
body: <p>I am developing a spring application using version 3.1.2 using tomcat 7 as the servlet manager.  I have noticed that the beans are being created twice, and I'm not sure how to prevent that.  I understand that the issue is somewhere in my web.xml or application context, but I've been unable to locate the source of the duplication.</p>
  
  <p>From the tomcat logs on startup, I see the following (paraphrasing for space):</p>
  
  <pre><code>May 24, 2013 9:33:03 AM org.springframework.web.context.ContextLoader initWebApplicationContext
  INFO: Root WebApplicationContext: initialization started
  May 24, 2013 9:33:03 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
  INFO: Refreshing Root WebApplicationContext: startup date [Fri May 24 09:33:03 CDT 2013]; root of context hierarchy
  May 24, 2013 9:33:03 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/kpi-reporter-servlet.xml]
  May 24, 2013 9:33:03 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@df9978: defining beans [...]; root of factory hierarchy
  May 24, 2013 9:33:04 AM org.springframework.web.context.ContextLoader initWebApplicationContext
  INFO: Root WebApplicationContext: initialization completed in 1260 ms
  May 24, 2013 9:33:04 AM org.springframework.web.servlet.FrameworkServlet initServletBean
  INFO: FrameworkServlet 'kpi-reporter': initialization started
  May 24, 2013 9:33:04 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
  INFO: Refreshing WebApplicationContext for namespace 'kpi-reporter-servlet': startup date [Fri May 24 09:33:04 CDT 2013]; parent: Root WebApplicationContext
  May 24, 2013 9:33:04 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
  INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/kpi-reporter-servlet.xml]
  May 24, 2013 9:33:04 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2821db: defining beans [...]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@df9978
  </code></pre>
  
  <p>Here is my web.xml and the application context configurations:</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &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;kpi-reporter&lt;/display-name&gt;
  
  &lt;servlet&gt;
    &lt;servlet-name&gt;kpi-reporter&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;kpi-reporter&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;default&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.css&lt;/url-pattern&gt;
    &lt;url-pattern&gt;*.gif&lt;/url-pattern&gt;
    &lt;url-pattern&gt;*.js&lt;/url-pattern&gt;
    &lt;url-pattern&gt;*.png&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;/WEB-INF/kpi-reporter-servlet.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;listener&gt;
    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>kpi-reporter-servlet.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
      http://www.springframework.org/schema/beans     
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
    &lt;context:component-scan base-package="."/&gt;
  
    &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"&gt;&lt;/property&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/"&gt;&lt;/property&gt;
      &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt;
    &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>If I remove the  statement in the kpi-reporter-servlet.xml, then the beans don't get defined at all.  If I move the context statement to the web.xml (along with the required imports) it still gets defined twice.  I am suspecting that somehow the web.xml is being called twice during startup.  </p>
  
  <p>I've checked the webapps directory, and I only have one file and directory present, the .war file used to deploy the application, and the directory it was unpacked into.</p>
  
  <p>Other .war applications I've developed also have this behavior, though they have similar xml files associated with them.</p>
  
  <p>Does anyone know why this may be happening?  I'm stumped over here.</p>
  
  <p>Thanks in advance,
  Max</p>