Convert Actuator sample to dynamic ports

This commit is contained in:
Dave Syer
2014-04-17 17:36:09 -07:00
parent 559009b8cf
commit f134e96053
19 changed files with 120 additions and 71 deletions

View File

@@ -53,7 +53,9 @@ 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;
@@ -195,6 +197,8 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
}
try {
childContext.refresh();
registerContainer(this.applicationContext,
childContext.getEmbeddedServletContainer());
}
catch (RuntimeException e) {
// No support currently for deploying a war with management.port=<different>,
@@ -207,6 +211,16 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
throw e;
}
}
};
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 {

View File

@@ -126,4 +126,5 @@ public class ManagementServerProperties implements SecurityPrequisite {
}
return null;
}
}