
1. Overview
In this article, we will learn the default URL base path of Spring Actuator and change it to a different one.
To learn more about Spring Actuator, refer to our articles.
2. Spring Boot Actuator dependency
The?spring-boot-actuator
?module provides all of Spring Boot’s production-ready features. The recommended way to enable the features is to add a dependency on the?spring-boot-starter-actuator
?“Starter”.
To add the actuator to a Maven-based project, add the following ‘Starter’ dependency:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies>
Since the Spring Boot (BOM) maintains the versions of dependencies, no need to specify the version for the actuator starter explicitly.
3. Spring Actuator Base path
If you are developing a web application, Spring Boot Actuator auto-configures all enabled endpoints to be exposed over HTTP.
The default convention is to use the?id
?of the endpoint with a prefix of?/actuator
?as the URL path. For example,?health
?is exposed as?/actuator/health
.
{"status":"UP"}
3.1. Configure different base path for Actuator
Sometimes, you want to customize the prefix for the management endpoints.
For example, your application might already use?/actuator
?for another purpose. You can use the?management.endpoints.web.base-path
?property to change the prefix for your management endpoint, as shown in the following example:
management.endpoints.web.base-path=/monitor
The preceding?application.properties
?example changes the endpoint from?/actuator/{id}
?to?/monitor/{id}
?(for example,?/monitor/info
).
3.2. Configure an individual endpoint to a different path
You can use the?management.endpoints.web.path-mapping
?property to map an endpoint to a different path.
The following example remaps?/actuator/
to /monitor/
and further maps the /monitor/health
?to?/monitor/healthcheck
:
management.endpoints.web.base-path=/monitor management.endpoints.web.path-mapping.health=healthcheck
Similarly, you can change the actuator base path and also the individual endpoint path.
If you hit the URL http://localhost:8080/monitor/healthcheck
after running the application, it returns the following response.
{"status":"UP"}
4. Conclusion
To sum up, we have learned the Spring actuator base path and configured it to a different path.