Fixes #54: stop servlet container if context fails to start

This commit is contained in:
Dave Syer 2013-09-20 16:28:43 +01:00
parent 97af88a8d8
commit 3c4f1a7a6f
3 changed files with 12 additions and 11 deletions

View File

@ -16,7 +16,6 @@
package org.springframework.boot.context.embedded; package org.springframework.boot.context.embedded;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
@ -188,9 +187,4 @@ public class AnnotationConfigEmbeddedWebApplicationContext extends
} }
} }
@Override
public final void refresh() throws BeansException, IllegalStateException {
super.refresh();
}
} }

View File

@ -35,6 +35,7 @@ import javax.servlet.ServletException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextException; import org.springframework.context.ApplicationContextException;
@ -114,6 +115,17 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
beanFactory.ignoreDependencyInterface(ServletContextAware.class); beanFactory.ignoreDependencyInterface(ServletContextAware.class);
} }
@Override
public final void refresh() throws BeansException, IllegalStateException {
try {
super.refresh();
}
catch (RuntimeException e) {
stopAndReleaseEmbeddedServletContainer();
throw e;
}
}
@Override @Override
protected void onRefresh() { protected void onRefresh() {
super.onRefresh(); super.onRefresh();

View File

@ -16,7 +16,6 @@
package org.springframework.boot.context.embedded; package org.springframework.boot.context.embedded;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -132,8 +131,4 @@ public class XmlEmbeddedWebApplicationContext extends EmbeddedWebApplicationCont
this.reader.loadBeanDefinitions(resources); this.reader.loadBeanDefinitions(resources);
} }
@Override
public final void refresh() throws BeansException, IllegalStateException {
super.refresh();
}
} }