protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
    if (ObjectUtils.identityToString(wac).equals(wac.getId())) {
      // The application context id is still set to its original default value
      // -> assign a more useful id based on available information
      if (this.contextId != null) {
        wac.setId(this.contextId);
      } else {
        // Generate default id...
        wac.setId(
            ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX
                + ObjectUtils.getDisplayString(getServletContext().getContextPath())
                + "/"
                + getServletName());
      }
    }

    wac.setServletContext(getServletContext());
    wac.setServletConfig(getServletConfig());
    wac.setNamespace(getNamespace());
    wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));

    // The wac environment's #initPropertySources will be called in any case when the context
    // is refreshed; do it eagerly here to ensure servlet property sources are in place for
    // use in any post-processing or initialization that occurs below prior to #refresh
    ConfigurableEnvironment env = wac.getEnvironment();
    if (env instanceof ConfigurableWebEnvironment) {
      ((ConfigurableWebEnvironment) env)
          .initPropertySources(getServletContext(), getServletConfig());
    }

    postProcessWebApplicationContext(wac);
    applyInitializers(wac);
    wac.refresh();
  }
 /**
  * {@inheritDoc}
  *
  * <p>Replace {@code Servlet}-related property sources.
  */
 @Override
 protected void initPropertySources() {
   super.initPropertySources();
   ConfigurableEnvironment env = this.getEnvironment();
   if (env instanceof ConfigurableWebEnvironment) {
     ((ConfigurableWebEnvironment) env).initPropertySources(this.servletContext, null);
   }
 }