/**
  * This implementation performs an actual refresh of this context's underlying bean factory,
  * shutting down the previous bean factory (if any) and initializing a fresh bean factory for the
  * next phase of the context's lifecycle.
  */
 @Override
 protected final void refreshBeanFactory() throws BeansException {
   if (hasBeanFactory()) {
     destroyBeans();
     closeBeanFactory();
   }
   try {
     DefaultListableBeanFactory beanFactory = createBeanFactory();
     beanFactory.setSerializationId(getId());
     customizeBeanFactory(beanFactory);
     loadBeanDefinitions(beanFactory);
     synchronized (this.beanFactoryMonitor) {
       this.beanFactory = beanFactory;
     }
   } catch (IOException ex) {
     throw new ApplicationContextException(
         "I/O error parsing bean definition source for " + getDisplayName(), ex);
   }
 }