title: How do I avoid doing the spring initialization twice?
body: <p>I am working on a Spring mvc application and have recently noticed that all of the servlets are registered twice upon startup. </p>
  
  <p>Have any of you an idea of why? If so, how I can avoid this while still keeping all of the functionality?</p>
  
  <p>Spring config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;  &lt;beans xmlns="http://www.springframework.org/schema/beans" 
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:context="http://www.springframework.org/schema/context"  
  xmlns:util="http://www.springframework.org/schema/util"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:mvc="http://www.springframework.org/schema/mvc" 
  xmlns:cache="http://www.springframework.org/schema/cache"
  xmlns:task="http://www.springframework.org/schema/task"
  xsi:schemaLocation="http://www.springframework.org/schema/beans  
  http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
  http://www.springframework.org/schema/context  
  http://www.springframework.org/schema/context/spring-context-3.1.xsd   
  http://www.springframework.org/schema/util 
  http://www.springframework.org/schema/util/spring-util-3.1.xsd
  http://www.springframework.org/schema/mvc 
  http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
  http://www.springframework.org/schema/cache 
  http://www.springframework.org/schema/cache/spring-cache.xsd
  http://www.springframework.org/schema/task
  http://www.springframework.org/schema/task/spring-task-3.1.xsd"&gt;  
  
  &lt;!-- SPRING MVC --&gt;  
  &lt;mvc:annotation-driven /&gt;
  &lt;context:annotation-config/&gt; 
  
  &lt;!-- Activates @Scheduled and @Async annotations for scheduling --&gt;
  &lt;task:annotation-driven /&gt;
  
  &lt;import resource="spring-security.xml"/&gt;
  
  &lt;mvc:resources mapping="/css/**" location="/css/" /&gt;
  &lt;mvc:resources mapping="/js/**" location="/js/" /&gt; 
  &lt;mvc:resources mapping="/images/**" location="/images/" /&gt;
  &lt;mvc:resources mapping="/robots.txt" location="robots.txt" /&gt;
  
  &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"&gt;
      &lt;property name="basename" value="messages"/&gt;
  &lt;/bean&gt; 
  
  &lt;mvc:interceptors&gt; 
       &lt;bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"&gt;
          &lt;property name="paramName" value="lang" /&gt;
      &lt;/bean&gt;
  &lt;/mvc:interceptors&gt;
  
  &lt;bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt;
      &lt;property name="defaultLocale" value="no"/&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/&gt;     
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/&gt;  
  &lt;bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/&gt;  
  
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;  
      &lt;property name="prefix" value="/WEB-INF/jsp/"/&gt;  
      &lt;property name="suffix" value=".jsp"/&gt;  
  &lt;/bean&gt;  
  
  &lt;cache:annotation-driven /&gt; 
  &lt;bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="classpath:ehcache.xml" p:shared="true"/&gt; 
  &lt;bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache"/&gt; 
  
   &lt;!-- Configure the multipart resolver --&gt;
  &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
      &lt;!-- one of the properties available; the maximum file size in bytes --&gt;
      &lt;property name="maxUploadSize" value="2000000"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>  </p>
  
  <p>Spring-security.xml</p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"  xmlns:beans="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:context="http://www.springframework.org/schema/context"  xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
         http://www.springframework.org/schema/security
         http://www.springframework.org/schema/security/spring-security-3.1.xsd
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
  &lt;context:component-scan base-package="com.snakeoil.diesel"/&gt;
  
  &lt;!-- SECURITY --&gt;
  &lt;global-method-security secured-annotations="enabled" /&gt;
  &lt;http auto-config='true' use-expressions="true" disable-url-rewriting="true"&gt;
      &lt;custom-filter position="CHANNEL_FILTER" ref="channelProcessingFilter"/&gt;
      &lt;intercept-url pattern="/secured/**" access="hasAnyRole('ADMIN')"/&gt;
      &lt;form-login login-page='/login.html' default-target-url='/secured/index.html' always-use-default-target='true'/&gt;
      &lt;logout logout-success-url="/loggedOut.html" delete-cookies="JSESSIONID" /&gt;
  &lt;/http&gt;
  
  &lt;beans:bean id="encoder" class="org.springframework.security.crypto.password.StandardPasswordEncoder"/&gt;
  
  &lt;!--  force https --&gt;
  &lt;beans:bean id="channelProcessingFilter" class="org.springframework.security.web.access.channel.ChannelProcessingFilter"&gt;
    &lt;beans:property name="channelDecisionManager" ref="channelDecisionManager"/&gt;
    &lt;beans:property name="securityMetadataSource"&gt;
      &lt;filter-security-metadata-source path-type="ant"&gt;
          &lt;intercept-url pattern="/**" access="REQUIRES_SECURE_CHANNEL" /&gt;
      &lt;/filter-security-metadata-source&gt;
    &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  
  
  &lt;beans:bean id="channelDecisionManager" class="org.springframework.security.web.access.channel.ChannelDecisionManagerImpl"&gt;
    &lt;beans:property name="channelProcessors"&gt;
      &lt;beans:list&gt;
      &lt;beans:ref bean="secureChannelHeaderProcessor"/&gt;
      &lt;beans:ref bean="insecureChannelHeaderProcessor"/&gt;
      &lt;/beans:list&gt;
    &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;Diesel&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;classpath:/diesel-servlet.xml&lt;/param-value&gt;
    &lt;/context-param&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;listener&gt;
       &lt;listener-class&gt;org.springframework.security.web.session.HttpSessionEventPublisher&lt;/listener-class&gt;
    &lt;/listener&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;diesel&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;classpath:/diesel-servlet.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;diesel&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;filter&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
  
     &lt;filter&gt;
          &lt;filter-name&gt;SetCharacterEncodingFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;encoding&lt;/param-name&gt;
              &lt;param-value&gt;UTF8&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;forceEncoding&lt;/param-name&gt;
              &lt;param-value&gt;true&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;SetCharacterEncodingFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;error-page&gt;
          &lt;error-code&gt;404&lt;/error-code&gt;
          &lt;location&gt;/redirect.html&lt;/location&gt;
      &lt;/error-page&gt;
  
    &lt;servlet&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;display-name&gt;dieselInitializer&lt;/display-name&gt;
      &lt;servlet-name&gt;dieselInitializer&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.snakeoil.diesel.web.DieselInitializer&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
      &lt;session-config&gt;
          &lt;session-timeout&gt;180&lt;/session-timeout&gt;
      &lt;/session-config&gt;
  
  
  &lt;/web-app&gt;
  </code></pre>