diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java index 611ea1ca20..8778d51a12 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointProperties.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Set; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.StringUtils; /** * Configuration properties for web management endpoints. @@ -59,7 +60,14 @@ public class WebEndpointProperties { } public void setBasePath(String basePath) { - this.basePath = basePath; + this.basePath = cleanBasePath(basePath); + } + + private String cleanBasePath(String basePath) { + if (StringUtils.hasText(basePath) && basePath.endsWith("/")) { + return basePath.substring(0, basePath.length() - 1); + } + return basePath; } public Set getExpose() { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointPropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointPropertiesTests.java index 9bac48531f..6a6010ec3c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointPropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/WebEndpointPropertiesTests.java @@ -33,4 +33,10 @@ public class WebEndpointPropertiesTests { assertThat(properties.getBasePath()).isEqualTo("/application"); } + @Test + public void basePathShouldBeCleaned() throws Exception { + WebEndpointProperties properties = new WebEndpointProperties(); + properties.setBasePath("/"); + assertThat(properties.getBasePath()).isEqualTo(""); + } }