@Override
 public void destroy() {
   appContext.close();
   if (appContext.getParent() instanceof ConfigurableApplicationContext) {
     ((ConfigurableApplicationContext) appContext.getParent()).close();
   }
   appContext = null;
 }
 /**
  * Fine the bean definition from a given context or from any of the parent contexts.
  *
  * @param beanName the bean name.
  * @return the bean definition.
  * @throws NoSuchBeanDefinitionException if the bean definition could not be found.
  */
 private BeanDefinition findBeanDefinition(String beanName) {
   ConfigurableApplicationContext current = springContext;
   BeanDefinition beanDef = null;
   do {
     try {
       return current.getBeanFactory().getBeanDefinition(beanName);
     } catch (NoSuchBeanDefinitionException e) {
       final ApplicationContext parent = current.getParent();
       if (parent != null && parent instanceof ConfigurableApplicationContext) {
         current = (ConfigurableApplicationContext) parent;
       } else {
         throw e;
       }
     }
   } while (beanDef == null && current != null);
   return beanDef;
 }
Exemplo n.º 3
0
 @Override
 public void stop() {
   if (this.context != null && isContainerRunning()) {
     this.containerRunning = false;
     // Publish the container stopped event before the context is closed.
     this.context.publishEvent(new ContainerStoppedEvent(this));
     this.context.close();
     ((ConfigurableApplicationContext) context.getParent()).close();
     if (logger.isInfoEnabled()) {
       final String message = "Stopped container: " + this.jvmName;
       final StringBuilder sb = new StringBuilder(LINE_SEPARATOR);
       sb.append(StringUtils.rightPad("", message.length(), "-"))
           .append(LINE_SEPARATOR)
           .append(message)
           .append(LINE_SEPARATOR)
           .append(StringUtils.rightPad("", message.length(), "-"))
           .append(LINE_SEPARATOR);
       logger.info(sb.toString());
     }
   }
 }
 @Override
 public void initialize(ConfigurableApplicationContext applicationContext) {
   ContainerAttributes containerAttributes =
       applicationContext.getParent().getBean(ContainerAttributes.class);
   applicationContext.setId(containerAttributes.getId());
 }