Harmonize management.server.context-path property
This commit moves management.server.context-path to management.server.servlet.context-path to align with the configuration key for the application's main context path. Closes gh-11359
This commit is contained in:
parent
5328508421
commit
afba8fed79
|
@ -36,7 +36,7 @@ public class WebEndpointProperties {
|
|||
|
||||
/**
|
||||
* Base path for Web endpoints. Relative to server.servlet.context-path or
|
||||
* management.server.context-path if management.server.port is configured.
|
||||
* management.server.servlet.context-path if management.server.port is configured.
|
||||
*/
|
||||
private String basePath = "/actuator";
|
||||
|
||||
|
|
|
@ -43,20 +43,16 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
|||
*/
|
||||
private Integer port;
|
||||
|
||||
@NestedConfigurationProperty
|
||||
private Ssl ssl;
|
||||
|
||||
/**
|
||||
* Network address that to which the management endpoints should bind to. Requires a
|
||||
* custom management.server.port.
|
||||
*/
|
||||
private InetAddress address;
|
||||
|
||||
/**
|
||||
* Management endpoint context-path. For instance, '/actuator'. Requires a custom
|
||||
* management.server.port.
|
||||
*/
|
||||
private String contextPath = "";
|
||||
private final Servlet servlet = new Servlet();
|
||||
|
||||
@NestedConfigurationProperty
|
||||
private Ssl ssl;
|
||||
|
||||
/**
|
||||
* Add the "X-Application-Context" HTTP header in each response.
|
||||
|
@ -82,14 +78,6 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
|||
this.port = port;
|
||||
}
|
||||
|
||||
public Ssl getSsl() {
|
||||
return this.ssl;
|
||||
}
|
||||
|
||||
public void setSsl(Ssl ssl) {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
public InetAddress getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
|
@ -98,25 +86,16 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
|||
this.address = address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the context path with no trailing slash (i.e. the '/' root context is
|
||||
* represented as the empty string).
|
||||
* @return the context path (no trailing slash)
|
||||
*/
|
||||
public String getContextPath() {
|
||||
return this.contextPath;
|
||||
public Ssl getSsl() {
|
||||
return this.ssl;
|
||||
}
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
Assert.notNull(contextPath, "ContextPath must not be null");
|
||||
this.contextPath = cleanContextPath(contextPath);
|
||||
public void setSsl(Ssl ssl) {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
private String cleanContextPath(String contextPath) {
|
||||
if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) {
|
||||
return contextPath.substring(0, contextPath.length() - 1);
|
||||
}
|
||||
return contextPath;
|
||||
public Servlet getServlet() {
|
||||
return this.servlet;
|
||||
}
|
||||
|
||||
public boolean getAddApplicationContextHeader() {
|
||||
|
@ -127,4 +106,38 @@ public class ManagementServerProperties implements SecurityPrerequisite {
|
|||
this.addApplicationContextHeader = addApplicationContextHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Servlet properties.
|
||||
*/
|
||||
public class Servlet {
|
||||
|
||||
/**
|
||||
* Management endpoint context-path. For instance, '/management'. Requires a
|
||||
* custom management.server.port.
|
||||
*/
|
||||
private String contextPath = "";
|
||||
|
||||
/**
|
||||
* Return the context path with no trailing slash (i.e. the '/' root context is
|
||||
* represented as the empty string).
|
||||
* @return the context path (no trailing slash)
|
||||
*/
|
||||
public String getContextPath() {
|
||||
return this.contextPath;
|
||||
}
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
Assert.notNull(contextPath, "ContextPath must not be null");
|
||||
this.contextPath = cleanContextPath(contextPath);
|
||||
}
|
||||
|
||||
private String cleanContextPath(String contextPath) {
|
||||
if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) {
|
||||
return contextPath.substring(0, contextPath.length() - 1);
|
||||
}
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -103,7 +103,8 @@ class ServletManagementChildContextConfiguration {
|
|||
ServerProperties serverProperties) {
|
||||
super.customize(webServerFactory, managementServerProperties,
|
||||
serverProperties);
|
||||
webServerFactory.setContextPath(managementServerProperties.getContextPath());
|
||||
webServerFactory.setContextPath(
|
||||
managementServerProperties.getServlet().getContextPath());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1112,7 +1112,7 @@
|
|||
"description": "Management endpoint context-path.",
|
||||
"defaultValue": "",
|
||||
"deprecation": {
|
||||
"replacement": "management.server.context-path",
|
||||
"replacement": "management.server.servlet.context-path",
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ManagementServerPropertiesTests {
|
|||
public void defaultManagementServerProperties() {
|
||||
ManagementServerProperties properties = new ManagementServerProperties();
|
||||
assertThat(properties.getPort()).isNull();
|
||||
assertThat(properties.getContextPath()).isEqualTo("");
|
||||
assertThat(properties.getServlet().getContextPath()).isEqualTo("");
|
||||
assertThat(properties.getAddApplicationContextHeader()).isEqualTo(false);
|
||||
}
|
||||
|
||||
|
@ -54,23 +54,23 @@ public class ManagementServerPropertiesTests {
|
|||
public void definedManagementServerProperties() {
|
||||
ManagementServerProperties properties = new ManagementServerProperties();
|
||||
properties.setPort(123);
|
||||
properties.setContextPath("/foo");
|
||||
properties.getServlet().setContextPath("/foo");
|
||||
assertThat(properties.getPort()).isEqualTo(123);
|
||||
assertThat(properties.getContextPath()).isEqualTo("/foo");
|
||||
assertThat(properties.getServlet().getContextPath()).isEqualTo("/foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trailingSlashOfContextPathIsRemoved() {
|
||||
ManagementServerProperties properties = new ManagementServerProperties();
|
||||
properties.setContextPath("/foo/");
|
||||
assertThat(properties.getContextPath()).isEqualTo("/foo");
|
||||
properties.getServlet().setContextPath("/foo/");
|
||||
assertThat(properties.getServlet().getContextPath()).isEqualTo("/foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void slashOfContextPathIsDefaultValue() {
|
||||
ManagementServerProperties properties = new ManagementServerProperties();
|
||||
properties.setContextPath("/");
|
||||
assertThat(properties.getContextPath()).isEqualTo("");
|
||||
properties.getServlet().setContextPath("/");
|
||||
assertThat(properties.getServlet().getContextPath()).isEqualTo("");
|
||||
}
|
||||
|
||||
public ManagementServerProperties load(String... environment) {
|
||||
|
|
|
@ -1080,8 +1080,8 @@ content into your application. Rather, pick only the properties that you need.
|
|||
# MANAGEMENT HTTP SERVER ({sc-spring-boot-actuator-autoconfigure}/web/server/ManagementServerProperties.{sc-ext}[ManagementServerProperties])
|
||||
management.server.add-application-context-header=false # Add the "X-Application-Context" HTTP header in each response. Requires a custom management.server.port.
|
||||
management.server.address= # Network address that to which the management endpoints should bind. Requires a custom management.server.port.
|
||||
management.server.context-path= # Management endpoint context-path. For instance, `/actuator`. Requires a custom management.server.port
|
||||
management.server.port= # Management endpoint HTTP port. Uses the same port as the application by default. Configure a different port to use management-specific SSL.
|
||||
management.server.servlet.context-path= # Management endpoint context-path. For instance, `/management`. Requires a custom management.server.port
|
||||
management.server.ssl.ciphers= # Supported SSL ciphers. Requires a custom management.port.
|
||||
management.server.ssl.client-auth= # Whether client authentication is wanted ("want") or needed ("need"). Requires a trust store. Requires a custom management.server.port.
|
||||
management.server.ssl.enabled= # Whether to enable SSL support. Requires a custom management.server.port.
|
||||
|
@ -1117,7 +1117,7 @@ content into your application. Rather, pick only the properties that you need.
|
|||
management.endpoints.web.enabled=true # Whether web endpoints are enabled
|
||||
management.endpoints.web.expose=info,health # Endpoint IDs that should be exposed or '*' for all.
|
||||
management.endpoints.web.exclude= # Endpoint IDs that should be excluded.
|
||||
management.endpoints.web.base-path=/actuator # Base path for Web endpoints. Relative to server.servlet.context-path or management.server.context-path if management.server.port is configured.
|
||||
management.endpoints.web.base-path=/actuator # Base path for Web endpoints. Relative to server.servlet.context-path or management.server.servlet.context-path if management.server.port is configured.
|
||||
management.endpoints.web.path-mapping= # Mapping between endpoint IDs and the path that should expose them.
|
||||
|
||||
# ENDPOINTS CORS CONFIGURATION ({sc-spring-boot-actuator-autoconfigure}/endpoint/web/servlet/CorsEndpointProperties.{sc-ext}[CorsEndpointProperties])
|
||||
|
|
|
@ -691,7 +691,8 @@ NOTE: Unless the management port has been configured to
|
|||
<<production-ready-customizing-management-server-port,expose endpoints using a different
|
||||
HTTP port>>, `management.endpoints.web.base-path` is relative to
|
||||
`server.servlet.context-path`. If `management.server.port` is configured,
|
||||
`management.endpoints.web.base-path` is relative to `management.server.context-path`.
|
||||
`management.endpoints.web.base-path` is relative to
|
||||
`management.server.servlet.context-path`.
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.server.port=0", "management.server.context-path=/management" })
|
||||
"management.server.port=0", "management.server.servlet.context-path=/management" })
|
||||
public class ManagementPortAndPathSampleActuatorApplicationTests {
|
||||
|
||||
@LocalServerPort
|
||||
|
|
|
@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"management.server.port=0", "management.server.address=127.0.0.1",
|
||||
"management.server.context-path:/admin" })
|
||||
"management.server.servlet.context-path:/admin" })
|
||||
public class ManagementAddressActuatorApplicationTests {
|
||||
|
||||
@LocalServerPort
|
||||
|
|
Loading…
Reference in New Issue