Understanding WebEndpointProperties in Spring Boot with Practical Examples

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:

  1. 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);
}
  1. Endpoint Exposure Control:
public static class Exposure {
    private Set<String> include = new LinkedHashSet<>();
    private Set<String> exclude = new LinkedHashSet<>();
    
    // Getter and setter methods
}
  1. 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"));
    }
}

Tags: java Spring Boot Actuator configuration Web Endpoints

Posted on Sun, 14 Jun 2026 17:33:53 +0000 by ludjer