Copy server customization to management context
If the actuator endpoints are configured on a different port then there are some settings in the main ServerProperties that we would like to re-use (e.g. the access log). The easiest way to do that is to just configure the management server using the same ServerProperties instance and then overwrite the things that are different (and stored in ManagementServerProperties). Fixes gh-1581
This commit is contained in:
@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
||||
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainer;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
@@ -222,6 +223,7 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||
assertThat(localServerPort, notNullValue());
|
||||
assertThat(localManagementPort, notNullValue());
|
||||
assertThat(localServerPort, not(equalTo(localManagementPort)));
|
||||
assertThat(applicationContext.getBean(ServerPortConfig.class).getCount(), equalTo(2));
|
||||
this.applicationContext.close();
|
||||
assertAllClosed();
|
||||
}
|
||||
@@ -303,10 +305,22 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||
|
||||
@Configuration
|
||||
public static class ServerPortConfig {
|
||||
|
||||
private int count = 0;
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ServerProperties serverProperties() {
|
||||
ServerProperties properties = new ServerProperties();
|
||||
ServerProperties properties = new ServerProperties() {
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
count++;
|
||||
super.customize(container);
|
||||
}
|
||||
};
|
||||
properties.setPort(ports.get().server);
|
||||
return properties;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user