From 3f9ca68812364321b8aae475f7d6a7c7a1afb8b1 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 3 Mar 2014 18:39:18 -0800 Subject: [PATCH] Tweak ConfigurableEmbeddedServletContainerFactory Update ConfigurableEmbeddedServletContainerFactory to no longer directly extend EmbeddedServletContainerFactory. --- .../ServerPropertiesAutoConfiguration.java | 2 ++ ...erverPropertiesAutoConfigurationTests.java | 10 ++++---- ...stractEmbeddedServletContainerFactory.java | 2 +- ...urableEmbeddedServletContainerFactory.java | 12 ++++++---- ...tEmbeddedServletContainerFactoryTests.java | 24 +++++++++---------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java index 60d2574ca7..c4740faff7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfiguration.java @@ -60,6 +60,8 @@ public class ServerPropertiesAutoConfiguration implements ApplicationContextAwar @Override public void customize(ConfigurableEmbeddedServletContainerFactory factory) { + // ServerProperties handles customization, this just checks we only have + // a single bean String[] serverPropertiesBeans = this.applicationContext .getBeanNamesForType(ServerProperties.class); Assert.state( diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java index 9fe5b0c7df..481c785ff6 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java @@ -48,7 +48,7 @@ import static org.junit.Assert.assertNotNull; */ public class ServerPropertiesAutoConfigurationTests { - private static ConfigurableEmbeddedServletContainerFactory containerFactory; + private static AbstractEmbeddedServletContainerFactory containerFactory; @Rule public ExpectedException thrown = ExpectedException.none(); @@ -57,8 +57,7 @@ public class ServerPropertiesAutoConfigurationTests { @Before public void init() { - containerFactory = Mockito - .mock(ConfigurableEmbeddedServletContainerFactory.class); + containerFactory = Mockito.mock(AbstractEmbeddedServletContainerFactory.class); } @After @@ -104,13 +103,12 @@ public class ServerPropertiesAutoConfigurationTests { PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); containerFactory = this.context - .getBean(ConfigurableEmbeddedServletContainerFactory.class); + .getBean(AbstractEmbeddedServletContainerFactory.class); ServerProperties server = this.context.getBean(ServerProperties.class); assertNotNull(server); // The server.port environment property was not explicitly set so the container // factory should take precedence... - assertEquals(3000, - ((AbstractEmbeddedServletContainerFactory) containerFactory).getPort()); + assertEquals(3000, containerFactory.getPort()); } @Test diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java index b3ff8fa810..767a101fe5 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java @@ -41,7 +41,7 @@ import org.springframework.util.Assert; * @author Dave Syer */ public abstract class AbstractEmbeddedServletContainerFactory implements - ConfigurableEmbeddedServletContainerFactory { + EmbeddedServletContainerFactory, ConfigurableEmbeddedServletContainerFactory { private static final String[] COMMON_DOC_ROOTS = { "src/main/webapp", "public", "static" }; diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainerFactory.java index 8169812c76..ff8073780f 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ConfigurableEmbeddedServletContainerFactory.java @@ -28,9 +28,9 @@ import java.util.concurrent.TimeUnit; * * @author Dave Syer * @see EmbeddedServletContainerFactory + * @see EmbeddedServletContainerCustomizer */ -public interface ConfigurableEmbeddedServletContainerFactory extends - EmbeddedServletContainerFactory { +public interface ConfigurableEmbeddedServletContainerFactory { /** * Sets the context path for the embedded servlet container. The context should start @@ -122,8 +122,8 @@ public interface ConfigurableEmbeddedServletContainerFactory extends /** * Sets {@link ServletContextInitializer} that should be applied in addition to - * {@link #getEmbeddedServletContainer(ServletContextInitializer...)} parameters. This - * method will replace any previously set or added initializers. + * {@link EmbeddedServletContainerFactory#getEmbeddedServletContainer(ServletContextInitializer...)} + * parameters. This method will replace any previously set or added initializers. * @param initializers the initializers to set * @see #addInitializers */ @@ -131,7 +131,9 @@ public interface ConfigurableEmbeddedServletContainerFactory extends /** * Add {@link ServletContextInitializer}s to those that should be applied in addition - * to {@link #getEmbeddedServletContainer(ServletContextInitializer...)} parameters. + * to + * {@link EmbeddedServletContainerFactory#getEmbeddedServletContainer(ServletContextInitializer...)} + * parameters. * @param initializers the initializers to add * @see #setInitializers */ diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java index 45ba4a8203..ca37714c99 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java @@ -84,7 +84,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void startServlet() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); this.container = factory .getEmbeddedServletContainer(exampleServletRegistration()); this.container.start(); @@ -93,7 +93,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void emptyServerWhenPortIsZero() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); factory.setPort(0); this.container = factory .getEmbeddedServletContainer(exampleServletRegistration()); @@ -104,7 +104,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void stopServlet() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); this.container = factory .getEmbeddedServletContainer(exampleServletRegistration()); this.container.start(); @@ -115,7 +115,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void restartWithKeepAlive() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); this.container = factory .getEmbeddedServletContainer(exampleServletRegistration()); this.container.start(); @@ -138,7 +138,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void startServletAndFilter() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); this.container = factory.getEmbeddedServletContainer( exampleServletRegistration(), new FilterRegistrationBean( new ExampleFilter())); @@ -148,7 +148,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void startBlocksUntilReadyToServe() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); final Date[] date = new Date[1]; this.container = factory .getEmbeddedServletContainer(new ServletContextInitializer() { @@ -170,7 +170,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void loadOnStartAfterContextIsInitialized() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); final InitCountingServlet servlet = new InitCountingServlet(); this.container = factory .getEmbeddedServletContainer(new ServletContextInitializer() { @@ -187,7 +187,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void specificPort() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); factory.setPort(8081); this.container = factory .getEmbeddedServletContainer(exampleServletRegistration()); @@ -198,7 +198,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void specificContextRoot() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); factory.setContextPath("/say"); this.container = factory .getEmbeddedServletContainer(exampleServletRegistration()); @@ -230,7 +230,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void doubleStop() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); this.container = factory .getEmbeddedServletContainer(exampleServletRegistration()); this.container.start(); @@ -240,7 +240,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void multipleConfigurations() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); ServletContextInitializer[] initializers = new ServletContextInitializer[6]; for (int i = 0; i < initializers.length; i++) { initializers[i] = mock(ServletContextInitializer.class); @@ -285,7 +285,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { @Test public void errorPage() throws Exception { - ConfigurableEmbeddedServletContainerFactory factory = getFactory(); + AbstractEmbeddedServletContainerFactory factory = getFactory(); factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/hello")); this.container = factory.getEmbeddedServletContainer( exampleServletRegistration(), errorServletRegistration());