title: Spring boot No WebApplicationContext found
body: <p>I have a simple spring boot app and I'm trying to get it up and running.  The config consists of an app context ( applicationContext.xml) XML with a bunch of beans in it.  I have a Spring application class:</p>
  
  <pre><code>@SpringBootApplication
  @Configuration
  @ImportResource("classpath:applicationContext.xml")
  public class WebCheckApplication {
  
      private static final Logger logger = Logger.getLogger(WebCheckApplication.class);
  
      public static void main(String[] args) {
          ApplicationContext ctx = SpringApplication.run(WebCheckApplication.class, args);
  
          if (logger.isDebugEnabled()) {
              logger.debug("Let's inspect the beans provided by Spring Boot:");
  
              String[] beanNames = ctx.getBeanDefinitionNames();
              Arrays.sort(beanNames);
              for (String beanName : beanNames) {
                  logger.debug(beanName);
              }
          }
      }
  }
  </code></pre>
  
  <p>And I have a @WebListener class that grabs a few beans from the WebContext from within the ServletContext:</p>
  
  <pre><code>@WebListener
  public class SystemPropertiesContextInitializer extends SysPropsAlertsFetcher implements ServletContextListener {
  
      private static final Logger logger = Logger.getLogger(SystemPropertiesContextInitializer.class);
  
      @Override
      public void contextDestroyed(ServletContextEvent sce) {
          //remove the SystemProperties and alert types map object from context
          sce.getServletContext().removeAttribute(BaseAuthenticatedController.SYSPROPS_KEY);
          sce.getServletContext().removeAttribute(BaseAuthenticatedController.ALERT_TYPES_MAP_KEY);
      }
  
      @Override
      public void contextInitialized(ServletContextEvent sce) {
  
          SysPropsDataAccess = (SystemPropertiesDataAccess) WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()).getBean("SystemPropertiesDataAccess");
          AlertsDataAccess = (AlertDataAccess) WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()).getBean("AlertsDataAccess");
          fetchObjects(sce.getServletContext());
      }
  }
  </code></pre>
  
  <p>When I attempt to start the app, I get the following error:</p>
  
  <pre><code>SEVERE: Exception sending context initialized event to listener instance of class web.SystemPropertiesContextInitializer
  java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
      at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:83)
      at .web.SystemPropertiesContextInitializer.contextInitialized(SystemPropertiesContextInitializer.java:31)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4994)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  </code></pre>
  
  <p>and it occurs at this line:</p>
  
  <pre><code>SysPropsDataAccess = (SystemPropertiesDataAccess) WebApplicationContextUtils.getRequiredWebApplicationContext(sce.getServletContext()).getBean("SystemPropertiesDataAccess");
  </code></pre>
  
  <p>It looks like Spring isn't creating a WebApplicationContext.</p>