Spring Boot's WebEndpointProperties class configures web endponit properties in actuator applications. This configuration class binds to properties prefixed with management.endpoints.web.
Key components of the class:
- Base Path Configuraton:
private String basePath = "/actuator";
public String getBasePath() {
return this.basePath;
}
public void setBasePath(String basePath) {
Assert.isTrue(basePath.isEmpty() || basePath.startsWith("/"),
"Base path must start with '/' or be empty");
this.basePath = cleanBasePath(basePath);
}
- Endpoint Exposure Control:
public static class Exposure {
private Set<String> include = new LinkedHashSet<>();
private Set<String> exclude = new LinkedHashSet<>();
// Getter and setter methods
}
- Path Mapping:
private final Map<String, String> pathMapping = new LinkedHashMap<>();
public Map<String, String> getPathMapping() {
return this.pathMapping;
}
Configuration example in application.properties:
management.endpoints.web.base-path=/monitoring
management.endpoints.web.exposure.include=health,metrics
management.endpoints.web.path-mapping.health=/system-status
Test case demonstrating validation:
public class WebEndpointPropertiesTest {
@Test
public void testValidBasePath() {
WebEndpointProperties properties = new WebEndpointProperties();
properties.setBasePath("/monitor");
assertEquals("/monitor", properties.getBasePath());
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidBasePath() {
WebEndpointProperties properties = new WebEndpointProperties();
properties.setBasePath("monitor"); // Missing leading slash
}
@Test
public void testPathMapping() {
WebEndpointProperties properties = new WebEndpointProperties();
properties.getPathMapping().put("health", "/status");
assertEquals("/status", properties.getPathMapping().get("health"));
}
}