/**
   * Register ServletContextAwareProcessor.
   *
   * @see ServletContextAwareProcessor
   */
  @Override
  protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    beanFactory.addBeanPostProcessor(new ServletContextAwareProcessor(this.servletContext));
    beanFactory.ignoreDependencyInterface(ServletContextAware.class);

    WebApplicationContextUtils.registerWebApplicationScopes(beanFactory, this.servletContext);
    WebApplicationContextUtils.registerEnvironmentBeans(beanFactory, this.servletContext);
  }
 /**
  * Prepare the {@link WebApplicationContext} with the given fully loaded {@link ServletContext}.
  * This method is usually called from {@link ServletContextInitializer#onStartup(ServletContext)}
  * and is similar to the functionality usually provided by a {@link ContextLoaderListener}.
  *
  * @param servletContext the operational servlet context
  */
 protected void prepareWebApplicationContext(ServletContext servletContext) {
   Object rootContext =
       servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
   if (rootContext != null) {
     if (rootContext == this) {
       throw new IllegalStateException(
           "Cannot initialize context because there is already a root application context present - "
               + "check whether you have multiple ServletContextInitializers!");
     } else {
       return;
     }
   }
   Log logger = LogFactory.getLog(ContextLoader.class);
   servletContext.log("Initializing Spring embedded WebApplicationContext");
   WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory(), getServletContext());
   WebApplicationContextUtils.registerEnvironmentBeans(getBeanFactory(), getServletContext());
   try {
     servletContext.setAttribute(
         WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this);
     if (logger.isDebugEnabled()) {
       logger.debug(
           "Published root WebApplicationContext as ServletContext attribute with name ["
               + WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE
               + "]");
     }
     if (logger.isInfoEnabled()) {
       long elapsedTime = System.currentTimeMillis() - getStartupDate();
       logger.info(
           "Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");
     }
   } catch (RuntimeException ex) {
     logger.error("Context initialization failed", ex);
     servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
     throw ex;
   } catch (Error ex) {
     logger.error("Context initialization failed", ex);
     servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);
     throw ex;
   }
 }
 /**
  * Register web-specific scopes ("request", "session", "globalSession") with the given
  * BeanFactory, as used by the WebApplicationContext.
  *
  * @param beanFactory the BeanFactory to configure
  */
 public static void registerWebApplicationScopes(ConfigurableListableBeanFactory beanFactory) {
   registerWebApplicationScopes(beanFactory, null);
 }