refined LifecycleProcessor exception handling, properly wrapping a start exception from a bean (SPR-7106)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
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 + "'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user