Sub topic 11
Using a Separate Management Port and Base Path
This chapter assumes you can add Actuator to a Spring Boot application, expose endpoints with management.endpoints.web.exposure.include, and read YAML configuration. Basic Spring Security knowledge helps for the last sections.
By default, Actuator endpoints are served by the same web server, on the same port, as your application. A request to /actuator/health and a request to /orders hit the same Tomcat connector. This is simple, but it has costs. Anything that can reach your application can also reach Actuator, and a traffic spike on the application port can starve health checks. Spring Boot lets you move Actuator to its own port, its own base path, or both.
Why separate the management endpoints
There are three common reasons.
- Network isolation. The application port faces the internet or a load balancer. The management port is reachable only from inside the cluster or a private network. A firewall rule or Kubernetes network policy then protects the endpoints without any application code.
- Resource isolation. Requests to the management port are handled by a separate server (or at least a separate connector). When the application's request threads are all busy, health and metrics requests can still be answered. This matters because a failed health check can cause an orchestrator to restart a pod that was only slow.
- Path hygiene. A custom base path avoids clashes with your own controllers and makes the default
/actuatorprefix less predictable.
None of these replace authentication. Treat separation as one layer of defense and Spring Security as another.
Changing the management port
Set management.server.port to serve Actuator on a different port.
management:
server:
port: 9090
endpoints:
web:
exposure:
include: health,info,metrics,prometheusWith this configuration, http://localhost:8080/actuator/health returns 404, and http://localhost:9090/actuator/health returns the health result. Spring Boot starts a second embedded web server (a child application context) that hosts only the management endpoints.
You can verify the behavior with curl.
curl -i http://localhost:8080/actuator/health
curl -i http://localhost:9090/actuator/healthThe first call returns 404 Not Found. The second returns 200 OK with a body such as {"status":"UP"}.
Port values and special cases
| Value of `management.server.port` | Effect |
|---|---|
| Not set | Actuator shares the main server port. |
| A number such as `9090` | Actuator runs on its own server on that port. |
| `-1` | Actuator HTTP endpoints are disabled entirely. JMX is unaffected. |
| `0` | A random free port is chosen. Useful in tests. |
Setting the port to -1 is a quick way to turn off all HTTP exposure while keeping JMX available, as opposed to deleting the include list.
Binding to a specific address
A different port still listens on all network interfaces by default. To restrict it to the loopback interface, set the address.
management:
server:
port: 9090
address: 127.0.0.1Now only processes on the same host can connect. This fits a sidecar agent that scrapes metrics locally. It does not fit Kubernetes probes, because the kubelet connects to the pod IP, not to the loopback address. In a container, leave the address unset and rely on network policies, or bind to the pod's own address.
Changing the base path
Two properties control the URL layout.
management.endpoints.web.base-pathchanges the prefix. The default is/actuator.management.endpoints.web.path-mapping.<id>renames a single endpoint.
management:
endpoints:
web:
base-path: /internal
path-mapping:
health: status
exposure:
include: health,info,metrics,prometheusThe health endpoint is now at /internal/status, and the metrics endpoint is at /internal/metrics. The Prometheus scrape path changes the same way, so a scrape configuration that still points at /actuator/prometheus will receive 404 responses. Update your monitoring configuration whenever you change paths.
You can set the base path to / to serve endpoints directly under the root, for example /health. Spring Boot allows this only when the management port is different from the application port. Otherwise the endpoint paths could collide with your controller mappings, and startup fails.
management:
server:
port: 9090
endpoints:
web:
base-path: /Discovery page
Actuator also serves a discovery page at the base path itself, for example /actuator. It lists the links to each exposed endpoint. You can turn it off if you do not want to advertise the endpoint list.
management:
endpoints:
web:
discovery:
enabled: falseA separate context path for the management server
When the management server runs on its own port, it can also have its own servlet context path. This is independent of server.servlet.context-path.
server:
servlet:
context-path: /shop
management:
server:
port: 9090
base-path: /ops
endpoints:
web:
base-path: /actuatorHere the application is served under /shop on port 8080. The management server uses management.server.base-path as its context path. The health endpoint is then at http://localhost:9090/ops/actuator/health.
Be careful with a shared port. If you leave the management port unset and the application has server.servlet.context-path=/shop, Actuator moves under that context as well. The health endpoint becomes /shop/actuator/health. Probes and scrapers that assume /actuator/health then fail. Setting a separate management port removes this coupling.
The following table summarizes how the properties combine.
| Setting | Controls |
|---|---|
| `server.port` | The application's port. |
| `management.server.port` | The management server's port. |
| `management.server.base-path` | The context path of the management server (only with a separate port). |
| `management.endpoints.web.base-path` | Prefix for all endpoints, default `/actuator`. |
| `management.endpoints.web.path-mapping.<id>` | Name of one endpoint under the prefix. |
How the request flows
The diagram shows how external clients, the platform, and Prometheus reach the two ports.
Both servers live in one JVM. If the process dies, both ports go down. Separation protects against network exposure and thread exhaustion on the main connector, not against a crash or a long garbage collection pause.
Security implications
Moving to another port changes how Spring Security sees the requests, and this causes common mistakes.
When the management port differs from the server port, Spring Boot creates the management web server as a child context. Spring Security's auto-configuration still applies to Actuator requests, but your own SecurityFilterChain beans need to match them. EndpointRequest.toAnyEndpoint() from the earlier securing chapter works in both setups, because it resolves paths from the Actuator configuration instead of hard-coded strings. Prefer it over requestMatchers("/actuator/**"). A hard-coded matcher breaks silently when you rename the base path, and the endpoints may end up either unprotected or blocked.
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
public class ManagementSecurityConfig {
@Bean
SecurityFilterChain managementSecurity(HttpSecurity http) throws Exception {
http.securityMatcher(EndpointRequest.toAnyEndpoint())
.authorizeHttpRequests(auth -> auth
.requestMatchers(EndpointRequest.to("health")).permitAll()
.anyRequest().hasRole("ACTUATOR"))
.httpBasic(Customizer.withDefaults());
return http.build();
}
}This chain survives a change of port or base path without edits.
Probes and scrapers on a separate port
Kubernetes probes must target the management port. Using the health groups from the earlier chapter, the container spec looks like this.
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 9090
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: 9090A frequent failure is leaving the probe on port 8080 after moving Actuator. The probe then receives 404, the kubelet counts it as a failure, and the pod is restarted in a loop. After any port or path change, check the manifests and the Prometheus scrape_configs as well.
Prometheus needs the matching port and path.
scrape_configs:
- job_name: orders-service
metrics_path: /internal/prometheus
static_configs:
- targets: ['orders:9090']If you changed base-path to /internal, metrics_path must be /internal/prometheus.
Management SSL
The management server can use its own TLS settings, independent of the main server. This is useful when the application terminates TLS but the internal port should stay plain HTTP, or the reverse.
server:
ssl:
enabled: true
key-store: classpath:app.p12
key-store-password: ${KEYSTORE_PASSWORD}
management:
server:
port: 9090
ssl:
enabled: falseHere the application uses HTTPS and the management port uses plain HTTP. If you do not set management.server.ssl.enabled, the management server inherits the main server's SSL configuration when the ports differ in Spring Boot versions that support this. Check your version's behavior explicitly if a probe fails with a TLS handshake error. Never put secrets in the file. The example reads the password from an environment variable.
Common errors
- 404 on the old path. After setting a port or base path, the old URL no longer works. Update clients, probes, and scrape jobs.
- Startup failure with
base-path: /. The root base path requires a distinct management port. - Probes restarting a healthy pod. The probe targets the application port while Actuator moved.
- Management port reachable from outside. A new port is open to every interface unless you restrict it with an address, a firewall, or a network policy.
- Hard-coded security matchers. Paths written as strings drift from the configuration. Use
EndpointRequest. - Tests that hard-code 9090. In integration tests, use
management.server.port=0and inject the value with@LocalManagementPort.
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalManagementPort;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = "management.server.port=0")
class ManagementPortTest {
@LocalManagementPort
int managementPort;
@Autowired
TestRestTemplate rest;
@Test
void healthIsServedOnManagementPort() {
ResponseEntity<String> response = rest.getForEntity(
"http://localhost:" + managementPort + "/actuator/health", String.class);
assertThat(response.getStatusCode().is2xxSuccessful()).isTrue();
}
}The @LocalManagementPort annotation lives in org.springframework.boot.test.web.server in Spring Boot 3.4 and later. In earlier 3.x releases it is in org.springframework.boot.test.web.server under the spring-boot-test module too, but in 2.x it was org.springframework.boot.web.server.LocalManagementPort. Match the import to your version.
Summary of the decision
Use a separate port when the application is internet-facing, when you run on Kubernetes, or when health checks must stay responsive under load. Keep the shared port for small internal services where the added configuration gives no benefit. In both cases, secure the endpoints, expose a short list, and verify the final URLs with curl before changing any probe or scrape configuration.
Exercise
An application sets management.server.port=9090 and management.endpoints.web.base-path=/internal. A Kubernetes liveness probe still requests /actuator/health/liveness on port 8080. What does the kubelet see, what is the likely result, and what are the correct probe path and port?
Show answer
The request on port 8080 for /actuator/health/liveness returns 404, because Actuator no longer runs there. The kubelet counts the probe as failed, and after the failure threshold it restarts the container, which can produce a restart loop even though the application is healthy. The probe should use port 9090 and the path /internal/health/liveness.
Exercise
Why does management.endpoints.web.base-path=/ fail at startup when the management port is not set, and what configuration fixes it?
Show answer
Without a separate port, Actuator endpoints and your own controllers share one server, so root-level endpoint paths such as /health could collide with controller mappings. Spring Boot rejects this. Setting management.server.port to a different port gives Actuator its own server, and the root base path is then allowed.