Remove server.context-path from actuator endpoints if port set

If the user sets the management.port, he wants some of the
server.* properties, but not the context-path. This change
restores the behaviour in 1.2.x.

Fixes gh-4401
pull/4632/head
Dave Syer 9 years ago
parent dd7d587ea8
commit 4488bac4c3

@ -236,6 +236,8 @@ public class EndpointWebMvcChildContextConfiguration {
this.server.customize(container);
// Then reset the error pages
container.setErrorPages(Collections.<ErrorPage>emptySet());
// and the context path
container.setContextPath("");
// and add the management-specific bits
container.setPort(this.managementServerProperties.getPort());
container.setAddress(this.managementServerProperties.getAddress());

@ -108,9 +108,16 @@ public class EndpointWebMvcAutoConfigurationTests {
private static ThreadLocal<Ports> ports = new ThreadLocal<Ports>();
private static ServerProperties server = new ServerProperties();
private static ManagementServerProperties management = new ManagementServerProperties();
@Before
public void grabPorts() {
ports.set(new Ports());
Ports values = new Ports();
ports.set(values);
server.setPort(values.server);
management.setPort(values.management);
}
@After
@ -171,8 +178,7 @@ public class EndpointWebMvcAutoConfigurationTests {
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.context-path=/admin");
management.setContextPath("/admin");
this.applicationContext.refresh();
assertContent("/controller", ports.get().server, "controlleroutput");
assertContent("/admin/endpoint", ports.get().management, "endpointoutput");
@ -186,8 +192,8 @@ public class EndpointWebMvcAutoConfigurationTests {
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
DifferentPortConfig.class, BaseConfiguration.class,
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"management.context-path=/admin", "server.context-path=/spring");
management.setContextPath("/admin");
server.setContextPath("/spring");
this.applicationContext.refresh();
assertContent("/spring/controller", ports.get().server, "controlleroutput");
assertContent("/admin/endpoint", ports.get().management, "endpointoutput");
@ -506,9 +512,9 @@ public class EndpointWebMvcAutoConfigurationTests {
EmbeddedServletContainerAutoConfiguration.class,
JacksonAutoConfiguration.class, EndpointAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
DispatcherServletAutoConfiguration.class,
DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class,
ServerPropertiesAutoConfiguration.class, WebMvcAutoConfiguration.class })
ServerPropertiesAutoConfiguration.class })
protected static class BaseConfiguration {
}
@ -551,7 +557,8 @@ public class EndpointWebMvcAutoConfigurationTests {
super.customize(container);
}
};
properties.setPort(ports.get().server);
properties.setPort(server.getPort());
properties.setContextPath(server.getContextPath());
return properties;
}
@ -574,9 +581,7 @@ public class EndpointWebMvcAutoConfigurationTests {
@Bean
public ManagementServerProperties managementServerProperties() {
ManagementServerProperties properties = new ManagementServerProperties();
properties.setPort(ports.get().management);
return properties;
return management;
}
@Bean

Loading…
Cancel
Save