Remove getEmbeddedServletContainers()
Remove the mutable getEmbeddedServletContainers() Map from EmbeddedWebApplicationContext and instead use the `namespace` to distinguish the management container. The ServerPortInfoApplicationContextInitializer class replaces the previous TestExecutionListener to exposes port properties (by listening for EmbeddedServletContainerInitializedEvents).
This commit is contained in:
@@ -53,9 +53,7 @@ import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoCo
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainer;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerException;
|
||||
import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -173,6 +171,7 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||
|
||||
final AnnotationConfigEmbeddedWebApplicationContext childContext = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||
childContext.setParent(this.applicationContext);
|
||||
childContext.setNamespace("management");
|
||||
childContext.setId(this.applicationContext.getId() + ":management");
|
||||
|
||||
// Register the ManagementServerChildContextConfiguration first followed
|
||||
@@ -197,8 +196,6 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||
}
|
||||
try {
|
||||
childContext.refresh();
|
||||
registerContainer(this.applicationContext,
|
||||
childContext.getEmbeddedServletContainer());
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
// No support currently for deploying a war with management.port=<different>,
|
||||
@@ -213,16 +210,6 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||
}
|
||||
};
|
||||
|
||||
private void registerContainer(ApplicationContext applicationContext,
|
||||
EmbeddedServletContainer embeddedServletContainer) {
|
||||
if (applicationContext instanceof EmbeddedWebApplicationContext) {
|
||||
((EmbeddedWebApplicationContext) applicationContext)
|
||||
.getEmbeddedServletContainers().put("management",
|
||||
embeddedServletContainer);
|
||||
// Maybe unregister it when it shuts down?
|
||||
}
|
||||
}
|
||||
|
||||
protected static enum ManagementServerPort {
|
||||
|
||||
DISABLE, SAME, DIFFERENT;
|
||||
|
||||
Reference in New Issue
Block a user