Restructure embedded web server packages

Rework `org.springframework.boot.context.embedded` to relocate classes
to `org.springframework.boot.web`. Packages are now organized around
the following areas:

Packages for shared concerns, for example the `WebServer` interface
to start/stop a server and the common configuration elements:
- org.springframework.boot.web.context
- org.springframework.boot.web.server

Servlet specific packages:
- org.springframework.boot.web.servlet.server
- org.springframework.boot.web.servlet.context
- org.springframework.boot.web.servlet.filter

Reactive specific packages:
- org.springframework.boot.web.reactive.context
- org.springframework.boot.web.reactive.server

Embedded server implementations (both reactive and servlet):
- org.springframework.boot.web.embedded

In addition:

- Rename `EmbeddedServletContainerFactory` to `ServletWebServerFactory`
  to align with the `ReactiveWebServerFactory`.
- Rename `EmbeddedWebApplicationContext` to
  `ServletWebServerApplicationContext` and
- Rename `EmbeddedReactiveWebApplicationContext` to
  `ReactiveWebServerApplicationContext`.
- Add checkstyle rules to restrict imports.
- Fixup all affected code to use the correct imports and local names.

Fixes gh-8532
This commit is contained in:
Phillip Webb
2017-03-07 11:26:11 -08:00
parent 7b388e5865
commit 67556ba8ea
263 changed files with 2821 additions and 3287 deletions

View File

@@ -28,9 +28,9 @@ import org.springframework.beans.BeanUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.boot.context.GenericReactiveWebApplicationContext;
import org.springframework.boot.test.mock.web.SpringBootMockServletContext;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext;
import org.springframework.boot.web.support.ServletContextApplicationContextInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextInitializer;
@@ -66,8 +66,8 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
* <p>
* The loader supports both standard {@link MergedContextConfiguration} as well as
* {@link WebMergedContextConfiguration}. If {@link WebMergedContextConfiguration} is used
* the context will either use a mock servlet environment, or start the full embedded
* servlet container.
* the context will either use a mock servlet environment, or start the full embedded web
* server.
* <p>
* If {@code @ActiveProfiles} are provided in the test class they will be used to create
* the application context.

View File

@@ -26,9 +26,9 @@ import java.lang.annotation.Target;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.context.ReactiveWebApplicationContext;
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AliasFor;
@@ -53,11 +53,11 @@ import org.springframework.web.context.WebApplicationContext;
* <li>Allows custom {@link Environment} properties to be defined using the
* {@link #properties() properties attribute}.</li>
* <li>Provides support for different {@link #webEnvironment() webEnvironment} modes,
* including the ability to start a fully running container listening on a
* including the ability to start a fully running web server listening on a
* {@link WebEnvironment#DEFINED_PORT defined} or {@link WebEnvironment#RANDOM_PORT
* random} port.</li>
* <li>Registers a {@link org.springframework.boot.test.web.client.TestRestTemplate
* TestRestTemplate} bean for use in web tests that are using a fully running container.
* TestRestTemplate} bean for use in web tests that are using a fully running web server.
* </li>
* </ul>
*
@@ -149,8 +149,8 @@ public @interface SpringBootTest {
}
/**
* Return if the environment uses an {@link EmbeddedWebApplicationContext}.
* @return if an {@link EmbeddedWebApplicationContext} is used.
* Return if the environment uses an {@link ServletWebServerApplicationContext}.
* @return if an {@link ServletWebServerApplicationContext} is used.
*/
public boolean isEmbedded() {
return this.embedded;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.
@@ -22,11 +22,11 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.boot.context.embedded.AbstractConfigurableEmbeddedServletContainer;
import org.springframework.boot.test.web.client.LocalHostUriTemplateHandler;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.client.TestRestTemplate.HttpClientOption;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.servlet.server.AbstractConfigurableServletWebServerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
@@ -106,9 +106,10 @@ class SpringBootTestContextCustomizer implements ContextCustomizer {
private boolean isSslEnabled(ApplicationContext context) {
try {
AbstractConfigurableEmbeddedServletContainer container = context
.getBean(AbstractConfigurableEmbeddedServletContainer.class);
return container.getSsl() != null && container.getSsl().isEnabled();
AbstractConfigurableServletWebServerFactory webServerFactory = context
.getBean(AbstractConfigurableServletWebServerFactory.class);
return webServerFactory.getSsl() != null
&& webServerFactory.getSsl().isEnabled();
}
catch (NoSuchBeanDefinitionException ex) {
return false;

View File

@@ -22,8 +22,8 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.boot.context.embedded.AbstractConfigurableReactiveWebServer;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.reactive.server.AbstractConfigurableReactiveWebServerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ConfigurableApplicationContext;
@@ -120,9 +120,9 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
private boolean isSslEnabled(ApplicationContext context) {
try {
AbstractConfigurableReactiveWebServer container = context
.getBean(AbstractConfigurableReactiveWebServer.class);
return container.getSsl() != null && container.getSsl().isEnabled();
AbstractConfigurableReactiveWebServerFactory webServerFactory = context
.getBean(AbstractConfigurableReactiveWebServerFactory.class);
return webServerFactory.getSsl() != null && webServerFactory.getSsl().isEnabled();
}
catch (NoSuchBeanDefinitionException ex) {
return false;

View File

@@ -21,10 +21,10 @@ import reactor.core.publisher.Mono;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.ReactiveWebApplicationContext;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.context.embedded.ReactiveWebServerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatReactiveWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatReactiveWebServerFactory;
import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext;
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@@ -89,7 +89,7 @@ public abstract class AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests
}
@Bean
public ReactiveWebServerFactory embeddedReactiveContainer() {
public ReactiveWebServerFactory webServerFactory() {
TomcatReactiveWebServerFactory factory = new TomcatReactiveWebServerFactory();
factory.setPort(this.port);
return factory;

View File

@@ -22,10 +22,10 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -37,13 +37,12 @@ import org.springframework.web.servlet.DispatcherServlet;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Base class for {@link SpringBootTest} tests configured to start an embedded servlet
* container.
* Base class for {@link SpringBootTest} tests configured to start an embedded web server.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
public abstract class AbstractSpringBootTestEmbeddedServletWebEnvironmentTests {
public abstract class AbstractSpringBootTestWebServerWebEnvironmentTests {
@LocalServerPort
private int port = 0;
@@ -104,8 +103,8 @@ public abstract class AbstractSpringBootTestEmbeddedServletWebEnvironmentTests {
}
@Bean
public EmbeddedServletContainerFactory embeddedServletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
public ServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.setPort(this.port);
return factory;
}

View File

@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DirtiesContext
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "value=123" })
public class SpringBootTestTestRestTemplateDefinedByUser
extends AbstractSpringBootTestEmbeddedServletWebEnvironmentTests {
extends AbstractSpringBootTestWebServerWebEnvironmentTests {
@Test
public void restTemplateIsUserDefined() throws Exception {

View File

@@ -36,7 +36,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT, properties = {
"server.port=0", "value=123" })
public class SpringBootTestWebEnvironmentDefinedPortTests
extends AbstractSpringBootTestEmbeddedServletWebEnvironmentTests {
extends AbstractSpringBootTestWebServerWebEnvironmentTests {
@Configuration
@EnableWebMvc

View File

@@ -20,7 +20,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.AbstractSpringBootTestEmbeddedServletWebEnvironmentTests.AbstractConfig;
import org.springframework.boot.test.context.AbstractSpringBootTestWebServerWebEnvironmentTests.AbstractConfig;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

View File

@@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@DirtiesContext
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "value=123" })
public class SpringBootTestWebEnvironmentRandomPortTests
extends AbstractSpringBootTestEmbeddedServletWebEnvironmentTests {
extends AbstractSpringBootTestWebServerWebEnvironmentTests {
@Test
public void testRestTemplateShouldUseBuilder() throws Exception {