Skip to content

Commit 67556ba

Browse files
committed
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 spring-projectsgh-8532
1 parent 7b388e5 commit 67556ba

File tree

263 files changed

+2821
-3287
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

263 files changed

+2821
-3287
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java

+24-25
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@
4545
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
4646
import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration;
4747
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
48-
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
4948
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
5049
import org.springframework.boot.autoconfigure.web.ServerProperties;
50+
import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration;
5151
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
5252
import org.springframework.boot.bind.RelaxedPropertyResolver;
53-
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
54-
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
55-
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
5653
import org.springframework.boot.context.event.ApplicationFailedEvent;
5754
import org.springframework.boot.context.properties.EnableConfigurationProperties;
58-
import org.springframework.boot.web.filter.ApplicationContextHeaderFilter;
55+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
56+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
57+
import org.springframework.boot.web.servlet.filter.ApplicationContextHeaderFilter;
58+
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
5959
import org.springframework.context.ApplicationContext;
6060
import org.springframework.context.ApplicationContextAware;
6161
import org.springframework.context.ApplicationEvent;
@@ -95,7 +95,7 @@
9595
@ConditionalOnWebApplication(type = Type.SERVLET)
9696
@EnableConfigurationProperties(ManagementServerProperties.class)
9797
@AutoConfigureAfter({ PropertyPlaceholderAutoConfiguration.class,
98-
EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class,
98+
ServletWebServerFactoryAutoConfiguration.class, WebMvcAutoConfiguration.class,
9999
RepositoryRestMvcAutoConfiguration.class, HypermediaAutoConfiguration.class,
100100
HttpMessageConvertersAutoConfiguration.class })
101101
public class EndpointWebMvcAutoConfiguration
@@ -138,13 +138,13 @@ public void afterSingletonsInstantiated() {
138138
.get(this.applicationContext.getEnvironment());
139139
}
140140
if (managementPort == ManagementServerPort.DIFFERENT) {
141-
if (this.applicationContext instanceof EmbeddedWebApplicationContext
142-
&& ((EmbeddedWebApplicationContext) this.applicationContext)
143-
.getEmbeddedWebServer() != null) {
141+
if (this.applicationContext instanceof ServletWebServerApplicationContext
142+
&& ((ServletWebServerApplicationContext) this.applicationContext)
143+
.getWebServer() != null) {
144144
createChildManagementContext();
145145
}
146146
else {
147-
logger.warn("Could not start embedded management container on "
147+
logger.warn("Could not start management web server on "
148148
+ "different port (management endpoints are still available "
149149
+ "through JMX)");
150150
}
@@ -166,49 +166,48 @@ public void afterSingletonsInstantiated() {
166166
}
167167

168168
private void createChildManagementContext() {
169-
AnnotationConfigEmbeddedWebApplicationContext childContext = new AnnotationConfigEmbeddedWebApplicationContext();
169+
AnnotationConfigServletWebServerApplicationContext childContext = new AnnotationConfigServletWebServerApplicationContext();
170170
childContext.setParent(this.applicationContext);
171171
childContext.setNamespace("management");
172172
childContext.setId(this.applicationContext.getId() + ":management");
173173
childContext.setClassLoader(this.applicationContext.getClassLoader());
174174
childContext.register(EndpointWebMvcChildContextConfiguration.class,
175175
PropertyPlaceholderAutoConfiguration.class,
176-
EmbeddedServletContainerAutoConfiguration.class,
176+
ServletWebServerFactoryAutoConfiguration.class,
177177
DispatcherServletAutoConfiguration.class);
178-
registerEmbeddedServletContainerFactory(childContext);
178+
registerServletWebServerFactory(childContext);
179179
CloseManagementContextListener.addIfPossible(this.applicationContext,
180180
childContext);
181181
childContext.refresh();
182182
managementContextResolver().setApplicationContext(childContext);
183183
}
184184

185-
private void registerEmbeddedServletContainerFactory(
186-
AnnotationConfigEmbeddedWebApplicationContext childContext) {
185+
private void registerServletWebServerFactory(
186+
AnnotationConfigServletWebServerApplicationContext childContext) {
187187
try {
188188
ConfigurableListableBeanFactory beanFactory = childContext.getBeanFactory();
189189
if (beanFactory instanceof BeanDefinitionRegistry) {
190190
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
191-
registry.registerBeanDefinition("embeddedServletContainerFactory",
192-
new RootBeanDefinition(
193-
determineEmbeddedServletContainerFactoryClass()));
191+
registry.registerBeanDefinition("ServletWebServerFactory",
192+
new RootBeanDefinition(determineServletWebServerFactoryClass()));
194193
}
195194
}
196195
catch (NoSuchBeanDefinitionException ex) {
197196
// Ignore and assume auto-configuration
198197
}
199198
}
200199

201-
private Class<?> determineEmbeddedServletContainerFactoryClass()
200+
private Class<?> determineServletWebServerFactoryClass()
202201
throws NoSuchBeanDefinitionException {
203-
Class<?> servletContainerFactoryClass = this.applicationContext
204-
.getBean(EmbeddedServletContainerFactory.class).getClass();
205-
if (cannotBeInstantiated(servletContainerFactoryClass)) {
206-
throw new FatalBeanException("EmbeddedServletContainerFactory implementation "
207-
+ servletContainerFactoryClass.getName() + " cannot be instantiated. "
202+
Class<?> factoryClass = this.applicationContext
203+
.getBean(ServletWebServerFactory.class).getClass();
204+
if (cannotBeInstantiated(factoryClass)) {
205+
throw new FatalBeanException("ServletWebServerFactory implementation "
206+
+ factoryClass.getName() + " cannot be instantiated. "
208207
+ "To allow a separate management port to be used, a top-level class "
209208
+ "or static inner class should be used instead");
210209
}
211-
return servletContainerFactoryClass;
210+
return factoryClass;
212211
}
213212

214213
private boolean cannotBeInstantiated(Class<?> clazz) {

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java

+41-41
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@
4040
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
4141
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
4242
import org.springframework.boot.autoconfigure.hateoas.HypermediaHttpMessageConverterConfiguration;
43-
import org.springframework.boot.autoconfigure.web.DefaultServletContainerCustomizer;
43+
import org.springframework.boot.autoconfigure.web.DefaultServletWebServerFactoryCustomizer;
4444
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
4545
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
4646
import org.springframework.boot.autoconfigure.web.ServerProperties;
47-
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
48-
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
49-
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
50-
import org.springframework.boot.context.embedded.EmbeddedWebServer;
51-
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
52-
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
53-
import org.springframework.boot.web.servlet.ErrorPage;
47+
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
48+
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory;
49+
import org.springframework.boot.web.server.ErrorPage;
50+
import org.springframework.boot.web.server.WebServer;
51+
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
52+
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
53+
import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer;
5454
import org.springframework.context.annotation.Bean;
5555
import org.springframework.context.annotation.Configuration;
5656
import org.springframework.context.annotation.Import;
@@ -69,7 +69,7 @@
6969

7070
/**
7171
* Configuration triggered from {@link EndpointWebMvcAutoConfiguration} when a new
72-
* {@link EmbeddedWebServer} running on a different port is required.
72+
* {@link WebServer} running on a different port is required.
7373
*
7474
* @author Dave Syer
7575
* @author Stephane Nicoll
@@ -109,8 +109,8 @@ public CompositeHandlerExceptionResolver compositeHandlerExceptionResolver() {
109109
}
110110

111111
@Bean
112-
public ServerCustomization serverCustomization() {
113-
return new ServerCustomization();
112+
public ServerFactoryCustomization serverCustomization() {
113+
return new ServerFactoryCustomization();
114114
}
115115

116116
@Bean
@@ -171,51 +171,51 @@ static class HypermediaConfiguration {
171171

172172
}
173173

174-
static class ServerCustomization
175-
implements EmbeddedServletContainerCustomizer, Ordered {
174+
static class ServerFactoryCustomization
175+
implements ServletWebServerFactoryCustomizer, Ordered {
176176

177177
@Autowired
178178
private ListableBeanFactory beanFactory;
179179

180-
// This needs to be lazily initialized because EmbeddedServletContainerCustomizer
180+
// This needs to be lazily initialized because web server customizer
181181
// instances get their callback very early in the context lifecycle.
182182
private ManagementServerProperties managementServerProperties;
183183

184184
private ServerProperties server;
185185

186-
private DefaultServletContainerCustomizer serverCustomizer;
186+
private DefaultServletWebServerFactoryCustomizer serverCustomizer;
187187

188188
@Override
189189
public int getOrder() {
190190
return 0;
191191
}
192192

193193
@Override
194-
public void customize(ConfigurableEmbeddedServletContainer container) {
194+
public void customize(ConfigurableServletWebServerFactory webServerFactory) {
195195
if (this.managementServerProperties == null) {
196196
this.managementServerProperties = BeanFactoryUtils
197197
.beanOfTypeIncludingAncestors(this.beanFactory,
198198
ManagementServerProperties.class);
199199
this.server = BeanFactoryUtils.beanOfTypeIncludingAncestors(
200200
this.beanFactory, ServerProperties.class);
201201
this.serverCustomizer = BeanFactoryUtils.beanOfTypeIncludingAncestors(
202-
this.beanFactory, DefaultServletContainerCustomizer.class);
202+
this.beanFactory, DefaultServletWebServerFactoryCustomizer.class);
203203
}
204204
// Customize as per the parent context first (so e.g. the access logs go to
205205
// the same place)
206-
this.serverCustomizer.customize(container);
206+
this.serverCustomizer.customize(webServerFactory);
207207
// Then reset the error pages
208-
container.setErrorPages(Collections.<ErrorPage>emptySet());
208+
webServerFactory.setErrorPages(Collections.<ErrorPage>emptySet());
209209
// and the context path
210-
container.setContextPath("");
210+
webServerFactory.setContextPath("");
211211
// and add the management-specific bits
212-
container.setPort(this.managementServerProperties.getPort());
212+
webServerFactory.setPort(this.managementServerProperties.getPort());
213213
if (this.managementServerProperties.getSsl() != null) {
214-
container.setSsl(this.managementServerProperties.getSsl());
214+
webServerFactory.setSsl(this.managementServerProperties.getSsl());
215215
}
216-
container.setServerHeader(this.server.getServerHeader());
217-
container.setAddress(this.managementServerProperties.getAddress());
218-
container.addErrorPages(new ErrorPage(this.server.getError().getPath()));
216+
webServerFactory.setServerHeader(this.server.getServerHeader());
217+
webServerFactory.setAddress(this.managementServerProperties.getAddress());
218+
webServerFactory.addErrorPages(new ErrorPage(this.server.getError().getPath()));
219219
}
220220

221221
}
@@ -343,8 +343,8 @@ public ModelAndView resolveException(HttpServletRequest request,
343343

344344
}
345345

346-
static abstract class AccessLogCustomizer<T extends EmbeddedServletContainerFactory>
347-
implements EmbeddedServletContainerCustomizer, Ordered {
346+
static abstract class AccessLogCustomizer<T extends ServletWebServerFactory>
347+
implements ServletWebServerFactoryCustomizer, Ordered {
348348

349349
private final Class<T> factoryClass;
350350

@@ -362,35 +362,35 @@ public int getOrder() {
362362
}
363363

364364
@Override
365-
public void customize(ConfigurableEmbeddedServletContainer container) {
366-
if (this.factoryClass.isInstance(container)) {
367-
customize(this.factoryClass.cast(container));
365+
public void customize(ConfigurableServletWebServerFactory serverFactory) {
366+
if (this.factoryClass.isInstance(serverFactory)) {
367+
customize(this.factoryClass.cast(serverFactory));
368368
}
369369
}
370370

371-
abstract void customize(T container);
371+
abstract void customize(T webServerFactory);
372372

373373
}
374374

375375
static class TomcatAccessLogCustomizer
376-
extends AccessLogCustomizer<TomcatEmbeddedServletContainerFactory> {
376+
extends AccessLogCustomizer<TomcatServletWebServerFactory> {
377377

378378
TomcatAccessLogCustomizer() {
379-
super(TomcatEmbeddedServletContainerFactory.class);
379+
super(TomcatServletWebServerFactory.class);
380380
}
381381

382382
@Override
383-
public void customize(TomcatEmbeddedServletContainerFactory container) {
384-
AccessLogValve accessLogValve = findAccessLogValve(container);
383+
public void customize(TomcatServletWebServerFactory serverFactory) {
384+
AccessLogValve accessLogValve = findAccessLogValve(serverFactory);
385385
if (accessLogValve == null) {
386386
return;
387387
}
388388
accessLogValve.setPrefix(customizePrefix(accessLogValve.getPrefix()));
389389
}
390390

391391
private AccessLogValve findAccessLogValve(
392-
TomcatEmbeddedServletContainerFactory container) {
393-
for (Valve engineValve : container.getEngineValves()) {
392+
TomcatServletWebServerFactory serverFactory) {
393+
for (Valve engineValve : serverFactory.getEngineValves()) {
394394
if (engineValve instanceof AccessLogValve) {
395395
return (AccessLogValve) engineValve;
396396
}
@@ -401,15 +401,15 @@ private AccessLogValve findAccessLogValve(
401401
}
402402

403403
static class UndertowAccessLogCustomizer
404-
extends AccessLogCustomizer<UndertowEmbeddedServletContainerFactory> {
404+
extends AccessLogCustomizer<UndertowServletWebServerFactory> {
405405

406406
UndertowAccessLogCustomizer() {
407-
super(UndertowEmbeddedServletContainerFactory.class);
407+
super(UndertowServletWebServerFactory.class);
408408
}
409409

410410
@Override
411-
public void customize(UndertowEmbeddedServletContainerFactory container) {
412-
container.setAccessLogPrefix(customizePrefix(container.getAccessLogPrefix()));
411+
public void customize(UndertowServletWebServerFactory serverFactory) {
412+
serverFactory.setAccessLogPrefix(customizePrefix(serverFactory.getAccessLogPrefix()));
413413
}
414414

415415
}

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfiguration.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
3333
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
3434
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
35-
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
35+
import org.springframework.boot.autoconfigure.web.ServletWebServerFactoryAutoConfiguration;
3636
import org.springframework.boot.bind.RelaxedPropertyResolver;
3737
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3838
import org.springframework.context.annotation.Bean;
@@ -66,7 +66,7 @@
6666
@ConditionalOnClass({ AgentServlet.class, ServletWrappingController.class })
6767
@Conditional(JolokiaCondition.class)
6868
@AutoConfigureBefore(ManagementWebSecurityAutoConfiguration.class)
69-
@AutoConfigureAfter(EmbeddedServletContainerAutoConfiguration.class)
69+
@AutoConfigureAfter(ServletWebServerFactoryAutoConfiguration.class)
7070
@EnableConfigurationProperties(JolokiaProperties.class)
7171
public class JolokiaAutoConfiguration {
7272

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ManagementServerProperties.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import org.springframework.boot.autoconfigure.security.SecurityPrerequisite;
2626
import org.springframework.boot.autoconfigure.security.SecurityProperties;
2727
import org.springframework.boot.autoconfigure.web.ServerProperties;
28-
import org.springframework.boot.context.embedded.Ssl;
2928
import org.springframework.boot.context.properties.ConfigurationProperties;
3029
import org.springframework.boot.context.properties.NestedConfigurationProperty;
30+
import org.springframework.boot.web.server.Ssl;
3131
import org.springframework.util.Assert;
3232
import org.springframework.util.StringUtils;
3333

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/TomcatPublicMetrics.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828

2929
import org.springframework.beans.BeansException;
3030
import org.springframework.boot.actuate.metrics.Metric;
31-
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
32-
import org.springframework.boot.context.embedded.EmbeddedWebServer;
33-
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer;
31+
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
32+
import org.springframework.boot.web.server.WebServer;
33+
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
3434
import org.springframework.context.ApplicationContext;
3535
import org.springframework.context.ApplicationContextAware;
3636

@@ -47,26 +47,26 @@ public class TomcatPublicMetrics implements PublicMetrics, ApplicationContextAwa
4747

4848
@Override
4949
public Collection<Metric<?>> metrics() {
50-
if (this.applicationContext instanceof EmbeddedWebApplicationContext) {
50+
if (this.applicationContext instanceof ServletWebServerApplicationContext) {
5151
Manager manager = getManager(
52-
(EmbeddedWebApplicationContext) this.applicationContext);
52+
(ServletWebServerApplicationContext) this.applicationContext);
5353
if (manager != null) {
5454
return metrics(manager);
5555
}
5656
}
5757
return Collections.emptySet();
5858
}
5959

60-
private Manager getManager(EmbeddedWebApplicationContext applicationContext) {
61-
EmbeddedWebServer embeddedWebServer = applicationContext.getEmbeddedWebServer();
62-
if (embeddedWebServer instanceof TomcatEmbeddedServletContainer) {
63-
return getManager((TomcatEmbeddedServletContainer) embeddedWebServer);
60+
private Manager getManager(ServletWebServerApplicationContext applicationContext) {
61+
WebServer webServer = applicationContext.getWebServer();
62+
if (webServer instanceof TomcatWebServer) {
63+
return getManager((TomcatWebServer) webServer);
6464
}
6565
return null;
6666
}
6767

68-
private Manager getManager(TomcatEmbeddedServletContainer servletContainer) {
69-
for (Container container : servletContainer.getTomcat().getHost()
68+
private Manager getManager(TomcatWebServer webServer) {
69+
for (Container container : webServer.getTomcat().getHost()
7070
.findChildren()) {
7171
if (container instanceof Context) {
7272
return ((Context) container).getManager();

0 commit comments

Comments
 (0)