diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/EmbeddedDatabaseAutoConfiguration.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/EmbeddedDatabaseAutoConfiguration.java index e6a21bf882..7addf3f01e 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/EmbeddedDatabaseAutoConfiguration.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/jdbc/EmbeddedDatabaseAutoConfiguration.java @@ -18,7 +18,6 @@ package org.springframework.bootstrap.autoconfigure.jdbc; import java.util.LinkedHashMap; import java.util.Map; -import java.util.concurrent.ExecutorService; import javax.annotation.PostConstruct; import javax.sql.DataSource; @@ -32,7 +31,6 @@ import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.Resource; -import org.springframework.core.task.AsyncUtils; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @@ -57,8 +55,6 @@ public class EmbeddedDatabaseAutoConfiguration { "org.hsqldb.Database"); } - private ExecutorService executorService; - // FIXME: DB platform @Value("${spring.jdbc.schema:classpath*:schema.sql}") private Resource[] schemaLocations = new Resource[0]; @@ -83,7 +79,7 @@ public class EmbeddedDatabaseAutoConfiguration { public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder() .setType(getEmbeddedDatabaseType()); - return AsyncUtils.submitVia(this.executorService, builder).build(); + return builder.build(); } public static EmbeddedDatabaseType getEmbeddedDatabaseType() { diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactory.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactory.java index 1c07bd3358..52906a2367 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactory.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactory.java @@ -27,7 +27,6 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.util.Assert; -import org.springframework.web.ServletContextInitializer; /** * Abstract base class for {@link EmbeddedServletContainerFactory} implementations. diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/EmbeddedServletContainerFactory.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/EmbeddedServletContainerFactory.java index d2dff44754..88ae40be3d 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/EmbeddedServletContainerFactory.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/EmbeddedServletContainerFactory.java @@ -18,7 +18,6 @@ package org.springframework.bootstrap.context.embedded; import org.springframework.bootstrap.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.web.ServletContextInitializer; /** * Factory interface that can be used to create {@link EmbeddedServletContainer}s. diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/EmbeddedWebApplicationContext.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/EmbeddedWebApplicationContext.java index e87daa4dc2..3d991cb16b 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/EmbeddedWebApplicationContext.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/EmbeddedWebApplicationContext.java @@ -40,7 +40,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextException; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.Resource; -import org.springframework.web.ServletContextInitializer; import org.springframework.web.context.ContextLoader; import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.ServletContextAware; @@ -48,7 +47,6 @@ import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.GenericWebApplicationContext; import org.springframework.web.context.support.ServletContextAwareProcessor; import org.springframework.web.context.support.ServletContextResource; -import org.springframework.web.context.support.WebApplicationContextServletContextAwareProcessor; import org.springframework.web.context.support.WebApplicationContextUtils; /** diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/FilterRegistrationBean.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/FilterRegistrationBean.java index 3e0800cfdd..f818556060 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/FilterRegistrationBean.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/FilterRegistrationBean.java @@ -29,7 +29,6 @@ import javax.servlet.ServletContext; import javax.servlet.ServletException; import org.springframework.util.Assert; -import org.springframework.web.ServletContextInitializer; /** * A {@link ServletContextInitializer} to register {@link Filter}s in a Servlet 3.0+ diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/RegistrationBean.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/RegistrationBean.java index f662c93c61..a4d38b1450 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/RegistrationBean.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/RegistrationBean.java @@ -23,7 +23,6 @@ import javax.servlet.Registration; import org.springframework.core.Conventions; import org.springframework.util.Assert; -import org.springframework.web.ServletContextInitializer; /** * Base class for {@link ServletRegistrationBean servlet} and diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/ServletContextInitializer.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/ServletContextInitializer.java new file mode 100644 index 0000000000..d771e042e3 --- /dev/null +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/ServletContextInitializer.java @@ -0,0 +1,53 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.context.embedded; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; + +import org.springframework.web.SpringServletContainerInitializer; +import org.springframework.web.WebApplicationInitializer; + +/** + * Interface used to configure a Servlet 3.0+ {@link ServletContext context} + * programmatically. Unlike {@link WebApplicationInitializer}, classes that implement this + * interface (and do not implement {@link WebApplicationInitializer}) will not be + * detected by {@link SpringServletContainerInitializer} and hence will not be + * automatically bootstrapped by the Servlet container. + * + *

+ * This interface is primarily designed to allow {@link ServletContextInitializer}s to be + * managed by Spring and not the Servlet container. + * + *

+ * For configuration examples see {@link WebApplicationInitializer}. + * + * @author Phillip Webb + * @see WebApplicationInitializer + */ +public interface ServletContextInitializer { + + /** + * Configure the given {@link ServletContext} with any servlets, filters, listeners + * context-params and attributes necessary for initialization. + * @param servletContext the {@code ServletContext} to initialize + * @throws ServletException if any call against the given {@code ServletContext} + * throws a {@code ServletException} + */ + void onStartup(ServletContext servletContext) throws ServletException; + +} diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/ServletRegistrationBean.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/ServletRegistrationBean.java index 73d35ff15f..d5673d5653 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/ServletRegistrationBean.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/ServletRegistrationBean.java @@ -28,7 +28,6 @@ import javax.servlet.ServletException; import javax.servlet.ServletRegistration; import org.springframework.util.Assert; -import org.springframework.web.ServletContextInitializer; /** * A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+ diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/WebApplicationContextServletContextAwareProcessor.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/WebApplicationContextServletContextAwareProcessor.java new file mode 100644 index 0000000000..9eaa7b726a --- /dev/null +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/WebApplicationContextServletContextAwareProcessor.java @@ -0,0 +1,56 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.context.embedded; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; + +import org.springframework.util.Assert; +import org.springframework.web.context.ConfigurableWebApplicationContext; +import org.springframework.web.context.support.ServletContextAwareProcessor; + +/** + * Variant of {@link ServletContextAwareProcessor} for use with a + * {@link ConfigurableWebApplicationContext}. Can be used when registering the processor + * can occur before the {@link ServletContext} or {@link ServletConfig} have been + * initialized. + * + * @author Phillip Webb + */ +public class WebApplicationContextServletContextAwareProcessor extends + ServletContextAwareProcessor { + + private final ConfigurableWebApplicationContext webApplicationContext; + + public WebApplicationContextServletContextAwareProcessor( + ConfigurableWebApplicationContext webApplicationContext) { + Assert.notNull(webApplicationContext, "WebApplicationContext must not be null"); + this.webApplicationContext = webApplicationContext; + } + + @Override + protected ServletContext getServletContext() { + ServletContext servletContext = this.webApplicationContext.getServletContext(); + return (servletContext != null ? servletContext : super.getServletContext()); + } + + @Override + protected ServletConfig getServletConfig() { + ServletConfig servletConfig = this.webApplicationContext.getServletConfig(); + return (servletConfig != null ? servletConfig : super.getServletConfig()); + } +} diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java index bc859b9c3c..80accec06e 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/jetty/JettyEmbeddedServletContainerFactory.java @@ -37,12 +37,12 @@ import org.springframework.bootstrap.context.embedded.EmbeddedServletContainer; import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.EmptyEmbeddedServletContainer; import org.springframework.bootstrap.context.embedded.ErrorPage; +import org.springframework.bootstrap.context.embedded.ServletContextInitializer; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; -import org.springframework.web.ServletContextInitializer; /** * {@link EmbeddedServletContainerFactory} that can be used to create diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/jetty/ServletContextInitializerConfiguration.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/jetty/ServletContextInitializerConfiguration.java index 1293411f7e..6e5136c70a 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/jetty/ServletContextInitializerConfiguration.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/jetty/ServletContextInitializerConfiguration.java @@ -23,8 +23,8 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppContext; +import org.springframework.bootstrap.context.embedded.ServletContextInitializer; import org.springframework.util.Assert; -import org.springframework.web.ServletContextInitializer; /** * Jetty {@link Configuration} that calls {@link ServletContextInitializer}s. diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/tomcat/ServletContextInitializerLifecycleListener.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/tomcat/ServletContextInitializerLifecycleListener.java index bd25bdde0a..6275cacee9 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/tomcat/ServletContextInitializerLifecycleListener.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/tomcat/ServletContextInitializerLifecycleListener.java @@ -22,8 +22,8 @@ import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleListener; import org.apache.catalina.core.StandardContext; +import org.springframework.bootstrap.context.embedded.ServletContextInitializer; import org.springframework.util.Assert; -import org.springframework.web.ServletContextInitializer; /** * Tomcat {@link LifecycleListener} that calls {@link ServletContextInitializer}s. diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java index e9f422977a..5080dadff2 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java @@ -43,11 +43,11 @@ import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerEx import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.EmptyEmbeddedServletContainer; import org.springframework.bootstrap.context.embedded.ErrorPage; +import org.springframework.bootstrap.context.embedded.ServletContextInitializer; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; -import org.springframework.web.ServletContextInitializer; /** * {@link EmbeddedServletContainerFactory} that can be used to create diff --git a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java index a5b473206f..13ab520346 100644 --- a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java +++ b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java @@ -44,7 +44,6 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.util.FileCopyUtils; import org.springframework.util.StreamUtils; -import org.springframework.web.ServletContextInitializer; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; diff --git a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/EmbeddedWebApplicationContextTests.java b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/EmbeddedWebApplicationContextTests.java index a79a335eed..96345b40cc 100644 --- a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/EmbeddedWebApplicationContextTests.java +++ b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/EmbeddedWebApplicationContextTests.java @@ -37,7 +37,6 @@ import org.springframework.context.ApplicationContextException; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.Ordered; -import org.springframework.web.ServletContextInitializer; import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.request.SessionScope; diff --git a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/MockEmbeddedServletContainerFactory.java b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/MockEmbeddedServletContainerFactory.java index 2cc8507d40..a32af3fe98 100644 --- a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/MockEmbeddedServletContainerFactory.java +++ b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/MockEmbeddedServletContainerFactory.java @@ -38,7 +38,6 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.springframework.bootstrap.context.embedded.EmbeddedServletContainer; import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.web.ServletContextInitializer; /** * Mock {@link EmbeddedServletContainerFactory}.