title: Error creating bean Spring with name while deploying My Application on Wildfly 14
body: <p>Hi am migrating my spring application from jboss 6 to wildfly 14.
  I'm using Spring version 3</p>
  <p>The application was deplyed with no issu in Jboss 6, When I tried de deploy it in Wildfly 14 I got the this exception:</p>
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationSessionListener' defined in &quot;/C:/Produits/LDEV-BACK/wildfly-14.0.1.Final-EXA/bin/content/muses-web.war/WEB-INF/classes/fr/bdf/muses/manager/ApplicationSessionListener.class&quot;: Initialization of bean failed; nested exception is java.lang.IllegalStateException: UT010041: The servlet context has already been initialized, you can only call this method from a ServletContainerInitializer or a ServletContextListener:
  </code></pre>
  <p>Is it possible de deploy a spring 3 application on Wildfly 14 ? If yes can someOne please guides me to resolve this.</p>
  <p>Here is my web.xml</p>
  
  <pre><code>&lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd&quot;
      version=&quot;3.1&quot;&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;myApp&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;welcome-file-list&gt;
          &lt;welcome-file&gt;catalogue-archive.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;myApp&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;error-page&gt;
          &lt;error-code&gt;403&lt;/error-code&gt;
          &lt;location&gt;/erreur/403.jsp&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;error-code&gt;405&lt;/error-code&gt;
          &lt;location&gt;/erreur/405.jsp&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;error-code&gt;408&lt;/error-code&gt;
          &lt;location&gt;/erreur/408.jsp&lt;/location&gt;
      &lt;/error-page&gt;
      &lt;error-page&gt;
          &lt;location&gt;/erreur/default.jsp&lt;/location&gt;
      &lt;/error-page&gt;
  
      &lt;security-constraint&gt;
          &lt;display-name&gt;MYAPP USERS&lt;/display-name&gt;
          &lt;web-resource-collection&gt;
              &lt;web-resource-name&gt;Public&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;/css/*&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/lib/*&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/img/*&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/wro/*&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/erreur/*&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/login-page.jsp&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/logout.jsp&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/auth.html&lt;/url-pattern&gt;
              &lt;url-pattern&gt;/auth/*&lt;/url-pattern&gt;
          &lt;/web-resource-collection&gt;
          &lt;user-data-constraint&gt;
              &lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;
          &lt;/user-data-constraint&gt;
      &lt;/security-constraint&gt;
  
      &lt;security-constraint&gt;
          &lt;display-name&gt;MYAPP USERS&lt;/display-name&gt;
          &lt;web-resource-collection&gt;
              &lt;web-resource-name&gt;AUTHENTICATED_RESOURCE&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
              &lt;http-method-omission&gt;OPTIONS&lt;/http-method-omission&gt;
          &lt;/web-resource-collection&gt;
          &lt;auth-constraint&gt;
              &lt;role-name&gt;*&lt;/role-name&gt;
          &lt;/auth-constraint&gt;
          &lt;user-data-constraint&gt;
              &lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;
          &lt;/user-data-constraint&gt;
      &lt;/security-constraint&gt;
  
      &lt;security-constraint&gt;
          &lt;display-name&gt;MYAPP admin&lt;/display-name&gt;
          &lt;web-resource-collection&gt;
              &lt;web-resource-name&gt;AUTHENTICATED_RESOURCE&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;/admin-MYAPP/*&lt;/url-pattern&gt;
          &lt;/web-resource-collection&gt;
          &lt;auth-constraint&gt;
              &lt;role-name&gt;superviseur&lt;/role-name&gt;
              &lt;role-name&gt;FU1UA1416&lt;/role-name&gt;
              &lt;role-name&gt;FU_UA1416&lt;/role-name&gt;
              &lt;role-name&gt;FU1UA2113&lt;/role-name&gt;
              &lt;role-name&gt;FU_UA2113&lt;/role-name&gt;
              &lt;role-name&gt;FU1UA1482&lt;/role-name&gt;
              &lt;role-name&gt;FU_UA1482&lt;/role-name&gt;
              &lt;role-name&gt;FU1UA2504&lt;/role-name&gt;
              &lt;role-name&gt;FU_UA2504&lt;/role-name&gt;
              &lt;role-name&gt;FU1UA2109&lt;/role-name&gt;
              &lt;role-name&gt;FU_UA2109&lt;/role-name&gt;
              &lt;role-name&gt;AU_MYAPP_RSP&lt;/role-name&gt;
          &lt;/auth-constraint&gt;
          &lt;user-data-constraint&gt;
              &lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;
          &lt;/user-data-constraint&gt;
      &lt;/security-constraint&gt;
  
      &lt;security-constraint&gt;
          &lt;display-name&gt;MYAPP debug&lt;/display-name&gt;
          &lt;web-resource-collection&gt;
              &lt;web-resource-name&gt;AUTHENTICATED_RESOURCE&lt;/web-resource-name&gt;
              &lt;url-pattern&gt;/debug-MYAPP/*&lt;/url-pattern&gt;
          &lt;/web-resource-collection&gt;
          &lt;auth-constraint&gt;
              &lt;role-name&gt;superviseur&lt;/role-name&gt;
              &lt;role-name&gt;FU_UA2109&lt;/role-name&gt;
              &lt;role-name&gt;FU_UA2113&lt;/role-name&gt;
              &lt;role-name&gt;FU1UA2113&lt;/role-name&gt;
          &lt;/auth-constraint&gt;
          &lt;user-data-constraint&gt;
              &lt;transport-guarantee&gt;CONFIDENTIAL&lt;/transport-guarantee&gt;
          &lt;/user-data-constraint&gt;
      &lt;/security-constraint&gt;
  
      &lt;security-role&gt;
          &lt;role-name&gt;*&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU1UA2113&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU1UA1416&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU_UA2109&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU1UA2109&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU_UA2113&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU_UA1416&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU1UA1482&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU_UA1482&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU1UA2504&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;FU_UA2504&lt;/role-name&gt;
      &lt;/security-role&gt;
      &lt;security-role&gt;
          &lt;role-name&gt;AU_MYAPP_RSP&lt;/role-name&gt;
      &lt;/security-role&gt;
  
      &lt;login-config&gt;
          &lt;auth-method&gt;FORM&lt;/auth-method&gt;
          &lt;realm-name&gt;ldapm&lt;/realm-name&gt;
          &lt;form-login-config&gt;
              &lt;form-login-page&gt;/loginController.html&lt;/form-login-page&gt;
              &lt;form-error-page&gt;/erreur/auth.jsp&lt;/form-error-page&gt;
          &lt;/form-login-config&gt;
      &lt;/login-config&gt;
  
      &lt;mime-mapping&gt;
          &lt;extension&gt;woff&lt;/extension&gt;
          &lt;mime-type&gt;application/font-woff&lt;/mime-type&gt;
      &lt;/mime-mapping&gt;
  
      &lt;mime-mapping&gt;
          &lt;extension&gt;tff&lt;/extension&gt;
          &lt;mime-type&gt;application/font-tff&lt;/mime-type&gt;
      &lt;/mime-mapping&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;encodingFilter&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;UTF-8&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;encodingFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;WebResourceOptimizer&lt;/filter-name&gt;
          &lt;filter-class&gt;ro.isdc.wro.http.WroFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;!-- &lt;filter&gt; &lt;filter-name&gt;WebResourceOptimizer&lt;/filter-name&gt; &lt;filter-class&gt;ro.isdc.wro.http.WroFilter&lt;/filter-class&gt; 
          &lt;init-param&gt; &lt;param-name&gt;configuration&lt;/param-name&gt; &lt;param-value&gt;${muses.wro4j.profile}&lt;/param-value&gt; 
          &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;gzipResources&lt;/param-name&gt; &lt;param-value&gt;FALSE&lt;/param-value&gt; 
          &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;cacheUpdatePeriod&lt;/param-name&gt; &lt;param-value&gt;60&lt;/param-value&gt; 
          &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;modelUpdatePeriod&lt;/param-name&gt; &lt;param-value&gt;600&lt;/param-value&gt; 
          &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;jmxEnabled&lt;/param-name&gt; &lt;param-value&gt;false&lt;/param-value&gt; 
          &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;disableCache&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; 
          &lt;/init-param&gt; &lt;/filter&gt; --&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;WebResourceOptimizer&lt;/filter-name&gt;
          &lt;url-pattern&gt;/wro/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  <p>Here is myApp-servlet.xm file</p>
  <pre><code>&lt;beans
   xmlns=&quot;http://www.springframework.org/schema/beans&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
      xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
      xmlns:jdbc=&quot;http://www.springframework.org/schema/jdbc&quot;
      xmlns:mvc=&quot;http://www.springframework.org/schema/mvc&quot;
      xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot; 
      xmlns:jee=&quot;http://www.springframework.org/schema/jee&quot;
      xsi:schemaLocation=&quot;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
       http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-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&quot;&gt;
      
      &lt;import resource=&quot;classpath*:/data-access-config.xml&quot; /&gt;
      
      &lt;context:component-scan base-package=&quot;fr.sg.myApp&quot;/&gt;
      
      &lt;mvc:resources mapping=&quot;/**&quot; location=&quot;/&quot; /&gt;
      
      &lt;mvc:annotation-driven /&gt;
      
      &lt;bean id=&quot;sessionListener&quot; class=&quot;fr.sg.myApp.manager.ApplicationSessionListener&quot;&gt;&lt;/bean&gt; 
      
      &lt;mvc:interceptors&gt;
          &lt;bean class=&quot;fr.sg.myApp.manager.CurrentUserInterceptor&quot;&gt;&lt;/bean&gt;
      &lt;/mvc:interceptors&gt; 
      
      &lt;bean id=&quot;viewResolver&quot;
          class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&gt;
          &lt;property name=&quot;viewClass&quot; value=&quot;org.springframework.web.servlet.view.JstlView&quot;/&gt;
          &lt;property name=&quot;prefix&quot; value=&quot;/&quot;/&gt;
          &lt;property name=&quot;suffix&quot; value=&quot;.jsp&quot;/&gt;
          &lt;property name=&quot;order&quot; value=&quot;0&quot;/&gt;
      &lt;/bean&gt; 
  &lt;/beans&gt;
  </code></pre>
  <p>And here is my Bean Spring</p>
  <pre><code>@Component
  public class ApplicationSessionListener implements HttpSessionListener,
          ApplicationContextAware {
      
      private static int totalActiveSessions;
      
      @Autowired
      private ReportService reportService;
      
      public static int getTotalActiveSession() {
          return totalActiveSessions;
      }
      
      @Override
      public void sessionCreated(HttpSessionEvent arg0) {
          totalActiveSessions++;
          
          HttpSession session = arg0.getSession();
          Date now = new Date(session.getCreationTime());
          reportService.createSession(session.getId(), now);
      }
      
      @Override
      public void sessionDestroyed(HttpSessionEvent arg0) {
          totalActiveSessions--;
          
          HttpSession session = arg0.getSession();
          Date now = new Date(session.getLastAccessedTime());
          reportService.updateSession(session.getId(), now);
      }
      
      @Override
      public void setApplicationContext(ApplicationContext applicationContext)
              throws BeansException {
          if (applicationContext instanceof WebApplicationContext) {
              ((WebApplicationContext) applicationContext).getServletContext()
                      .addListener(this);
          } else {
              // Either throw an exception or fail gracefully, up to you
              throw new RuntimeException(
                      &quot;Must be inside a web application context&quot;);
          }
      }
  }
  </code></pre>