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
This commit is contained in:
parent
dd7d587ea8
commit
4488bac4c3
|
|
@ -236,6 +236,8 @@ public class EndpointWebMvcChildContextConfiguration {
|
||||||
this.server.customize(container);
|
this.server.customize(container);
|
||||||
// Then reset the error pages
|
// Then reset the error pages
|
||||||
container.setErrorPages(Collections.<ErrorPage>emptySet());
|
container.setErrorPages(Collections.<ErrorPage>emptySet());
|
||||||
|
// and the context path
|
||||||
|
container.setContextPath("");
|
||||||
// and add the management-specific bits
|
// and add the management-specific bits
|
||||||
container.setPort(this.managementServerProperties.getPort());
|
container.setPort(this.managementServerProperties.getPort());
|
||||||
container.setAddress(this.managementServerProperties.getAddress());
|
container.setAddress(this.managementServerProperties.getAddress());
|
||||||
|
|
|
||||||
|
|
@ -108,9 +108,16 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
private static ThreadLocal<Ports> ports = new ThreadLocal<Ports>();
|
private static ThreadLocal<Ports> ports = new ThreadLocal<Ports>();
|
||||||
|
|
||||||
|
private static ServerProperties server = new ServerProperties();
|
||||||
|
|
||||||
|
private static ManagementServerProperties management = new ManagementServerProperties();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void grabPorts() {
|
public void grabPorts() {
|
||||||
ports.set(new Ports());
|
Ports values = new Ports();
|
||||||
|
ports.set(values);
|
||||||
|
server.setPort(values.server);
|
||||||
|
management.setPort(values.management);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
@ -171,8 +178,7 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
|
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
|
||||||
DifferentPortConfig.class, BaseConfiguration.class,
|
DifferentPortConfig.class, BaseConfiguration.class,
|
||||||
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
|
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
|
||||||
EnvironmentTestUtils.addEnvironment(this.applicationContext,
|
management.setContextPath("/admin");
|
||||||
"management.context-path=/admin");
|
|
||||||
this.applicationContext.refresh();
|
this.applicationContext.refresh();
|
||||||
assertContent("/controller", ports.get().server, "controlleroutput");
|
assertContent("/controller", ports.get().server, "controlleroutput");
|
||||||
assertContent("/admin/endpoint", ports.get().management, "endpointoutput");
|
assertContent("/admin/endpoint", ports.get().management, "endpointoutput");
|
||||||
|
|
@ -186,8 +192,8 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
|
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
|
||||||
DifferentPortConfig.class, BaseConfiguration.class,
|
DifferentPortConfig.class, BaseConfiguration.class,
|
||||||
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
|
EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
|
||||||
EnvironmentTestUtils.addEnvironment(this.applicationContext,
|
management.setContextPath("/admin");
|
||||||
"management.context-path=/admin", "server.context-path=/spring");
|
server.setContextPath("/spring");
|
||||||
this.applicationContext.refresh();
|
this.applicationContext.refresh();
|
||||||
assertContent("/spring/controller", ports.get().server, "controlleroutput");
|
assertContent("/spring/controller", ports.get().server, "controlleroutput");
|
||||||
assertContent("/admin/endpoint", ports.get().management, "endpointoutput");
|
assertContent("/admin/endpoint", ports.get().management, "endpointoutput");
|
||||||
|
|
@ -506,9 +512,9 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
EmbeddedServletContainerAutoConfiguration.class,
|
EmbeddedServletContainerAutoConfiguration.class,
|
||||||
JacksonAutoConfiguration.class, EndpointAutoConfiguration.class,
|
JacksonAutoConfiguration.class, EndpointAutoConfiguration.class,
|
||||||
HttpMessageConvertersAutoConfiguration.class,
|
HttpMessageConvertersAutoConfiguration.class,
|
||||||
DispatcherServletAutoConfiguration.class,
|
DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||||
ManagementServerPropertiesAutoConfiguration.class,
|
ManagementServerPropertiesAutoConfiguration.class,
|
||||||
ServerPropertiesAutoConfiguration.class, WebMvcAutoConfiguration.class })
|
ServerPropertiesAutoConfiguration.class })
|
||||||
protected static class BaseConfiguration {
|
protected static class BaseConfiguration {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -551,7 +557,8 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
super.customize(container);
|
super.customize(container);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
properties.setPort(ports.get().server);
|
properties.setPort(server.getPort());
|
||||||
|
properties.setContextPath(server.getContextPath());
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -574,9 +581,7 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ManagementServerProperties managementServerProperties() {
|
public ManagementServerProperties managementServerProperties() {
|
||||||
ManagementServerProperties properties = new ManagementServerProperties();
|
return management;
|
||||||
properties.setPort(ports.get().management);
|
|
||||||
return properties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue