Browse Source

refined LifecycleProcessor exception handling, properly wrapping a start exception from a bean (SPR-7106)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3353 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
927346144c
  1. 9
      org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java
  2. 8
      org.springframework.context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

9
org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

@ -1007,11 +1007,16 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader @@ -1007,11 +1007,16 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
publishEvent(new ContextClosedEvent(this));
}
catch (Throwable ex) {
logger.error("Exception thrown from ApplicationListener handling ContextClosedEvent", ex);
logger.warn("Exception thrown from ApplicationListener handling ContextClosedEvent", ex);
}
// Stop all Lifecycle beans, to avoid delays during individual destruction.
getLifecycleProcessor().onClose();
try {
getLifecycleProcessor().onClose();
}
catch (Throwable ex) {
logger.warn("Exception thrown from LifecycleProcessor on context close", ex);
}
// Destroy all cached singletons in the context's BeanFactory.
destroyBeans();

8
org.springframework.context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

@ -34,6 +34,7 @@ import org.springframework.beans.factory.BeanFactory; @@ -34,6 +34,7 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.Lifecycle;
import org.springframework.context.LifecycleProcessor;
import org.springframework.context.Phased;
@ -161,7 +162,12 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor @@ -161,7 +162,12 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
if (logger.isDebugEnabled()) {
logger.debug("Starting bean '" + beanName + "' of type [" + bean.getClass() + "]");
}
bean.start();
try {
bean.start();
}
catch (Throwable ex) {
throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex);
}
if (logger.isDebugEnabled()) {
logger.debug("Successfully started bean '" + beanName + "'");
}

Loading…
Cancel
Save