Extract DispatcherServletAutoConfiguration so it can be used independently

This commit is contained in:
Dave Syer
2013-09-19 10:27:54 +01:00
parent a1517de6db
commit 5b1503d07d
6 changed files with 107 additions and 64 deletions

View File

@@ -298,11 +298,17 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
* @param servletContext the operational servlet context
*/
protected void prepareEmbeddedWebApplicationContext(ServletContext servletContext) {
if (servletContext
.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
throw new IllegalStateException(
"Cannot initialize context because there is already a root application context present - "
+ "check whether you have multiple ServletContextInitializer!");
Object rootContext = servletContext
.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
if (rootContext != null) {
if (rootContext == this) {
throw new IllegalStateException(
"Cannot initialize context because there is already a root application context present - "
+ "check whether you have multiple ServletContextInitializers!");
}
else {
return;
}
}
Log logger = LogFactory.getLog(ContextLoader.class);
servletContext.log("Initializing Spring embedded WebApplicationContext");