We’ll go over how to enable and disable actuator endpoints in a spring boot application in this post. To control actuator endpoints, the Spring Boot framework supports multiple configurations in application properties. It is possible to enable or disable all actuator endpoints, as well as particular endpoints. The spring boot security framework can be used to secure the actuator urls in the spring boot application.
How to Enable Spring Boot Actuator
To enable spring boot actuator, add the following two spring boot dependencies to the pom.xml file. Spring-boot-starter-actuator and spring-boot-starter-web are required dependencies. All actuator endpoints supported by spring boot are included in the spring-boot-starter-actuator dependency. The actuator endpoints are exposed in the web through the spring-boot-starter-web dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Default endpoints exposed in Spring Boot Actuator
All actuator endpoints urls except the shutdown url are enabled if the spring boot actuator dependencies are added to the pom.xml file. However, the web exposes two endpoint urls: /actuator and /actuator/health, which the spring boot application may access. The actuator’s default url port is 8080.
All available endpoints are shown at http://localhost:8080/actuator. The spring boot application’s health can be viewed via http://localhost:8080/actuator/health.
http://localhost:8080/actuator/
{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"health":{"href":"http://localhost:8080/actuator/health","templated":false},"health-path":{"href":"http://localhost:8080/actuator/health/{*path}","templated":true}}}
Expose all actuator endpoints
All actuator endpoints can be exposed by adding a configuration property to the application.properties file. The property exposes all urls except the shutdown url. You may see a list of all available endpoints using the actuator url http://localhost:8080/actuator.
application.properties
management.endpoints.web.exposure.include=*
{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"beans":{"href":"http://localhost:8080/actuator/beans","templated":false},"caches":{"href":"http://localhost:8080/actuator/caches","templated":false},"caches-cache":{"href":"http://localhost:8080/actuator/caches/{cache}","templated":true},"health-path":{"href":"http://localhost:8080/actuator/health/{*path}","templated":true},"health":{"href":"http://localhost:8080/actuator/health","templated":false},"info":{"href":"http://localhost:8080/actuator/info","templated":false},"conditions":{"href":"http://localhost:8080/actuator/conditions","templated":false},"configprops":{"href":"http://localhost:8080/actuator/configprops","templated":false},"configprops-prefix":{"href":"http://localhost:8080/actuator/configprops/{prefix}","templated":true},"env-toMatch":{"href":"http://localhost:8080/actuator/env/{toMatch}","templated":true},"env":{"href":"http://localhost:8080/actuator/env","templated":false},"loggers-name":{"href":"http://localhost:8080/actuator/loggers/{name}","templated":true},"loggers":{"href":"http://localhost:8080/actuator/loggers","templated":false},"heapdump":{"href":"http://localhost:8080/actuator/heapdump","templated":false},"threaddump":{"href":"http://localhost:8080/actuator/threaddump","templated":false},"metrics-requiredMetricName":{"href":"http://localhost:8080/actuator/metrics/{requiredMetricName}","templated":true},"metrics":{"href":"http://localhost:8080/actuator/metrics","templated":false},"scheduledtasks":{"href":"http://localhost:8080/actuator/scheduledtasks","templated":false},"mappings":{"href":"http://localhost:8080/actuator/mappings","templated":false}}}
Exclude all endpoints to expose
All endpoints exposed on the web can be excluded in Spring Boot. The following setting will prevent all actuator endpoints from being exposed on the web. The endpoint url for the actuator is http://localhost:8080/actuator. All other endpoints will be hidden and will not be shown or exposed.
application.properties
management.endpoints.web.exposure.exclude=*
{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false}}}
Expose a specific endpoint
Only the configured endpoints will be exposed using the following command. The remaining endpoints will not be exposed to the web and will be unavailable.
application.properties
management.endpoints.web.exposure.exclude=*
management.endpoints.web.exposure.include=health,info
{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"health":{"href":"http://localhost:8080/actuator/health","templated":false},"health-path":{"href":"http://localhost:8080/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:8080/actuator/info","templated":false}}}
Disable all endpoints
In the spring boot application, the following command will disable all actuator endpoints. The url cannot be used to access the endpoint. In this instance, the actuator endpoint address http://localhost:8080/actuator will not return any results.
application.properties
management.endpoints.enabled-by-default=false
{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false}}}
Enable required endpoint urls
Spring Boot provides the ability to enable a specific set of endpoints. The configuration below will allow you to enable the endpoint url that you need to expose on the web. The remaining endpoint urls are disabled and inaccessible.
application.properties
management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true
management.endpoint.info.enabled=true
management.endpoints.web.exposure.include=health,info
{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"health":{"href":"http://localhost:8080/actuator/health","templated":false},"health-path":{"href":"http://localhost:8080/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:8080/actuator/info","templated":false}}}
Disable specific endpoint
By specifying enabled=false in the configuration, the specific endpoint can be disabled. In this instance, just the specified endpoints can be disabled. The remaining endpoints are also reachable.
application.properties
management.endpoints.enabled-by-default=true
management.endpoint.health.enabled=false
management.endpoint.info.enabled=false
management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.exclude=health,info
{"_links":{"self":{"href":"http://localhost:8080/actuator","templated":false},"beans":{"href":"http://localhost:8080/actuator/beans","templated":false},"caches":{"href":"http://localhost:8080/actuator/caches","templated":false},"caches-cache":{"href":"http://localhost:8080/actuator/caches/{cache}","templated":true},"conditions":{"href":"http://localhost:8080/actuator/conditions","templated":false},"shutdown":{"href":"http://localhost:8080/actuator/shutdown","templated":false},"configprops":{"href":"http://localhost:8080/actuator/configprops","templated":false},"configprops-prefix":{"href":"http://localhost:8080/actuator/configprops/{prefix}","templated":true},"env-toMatch":{"href":"http://localhost:8080/actuator/env/{toMatch}","templated":true},"env":{"href":"http://localhost:8080/actuator/env","templated":false},"loggers-name":{"href":"http://localhost:8080/actuator/loggers/{name}","templated":true},"loggers":{"href":"http://localhost:8080/actuator/loggers","templated":false},"heapdump":{"href":"http://localhost:8080/actuator/heapdump","templated":false},"threaddump":{"href":"http://localhost:8080/actuator/threaddump","templated":false},"metrics-requiredMetricName":{"href":"http://localhost:8080/actuator/metrics/{requiredMetricName}","templated":true},"metrics":{"href":"http://localhost:8080/actuator/metrics","templated":false},"scheduledtasks":{"href":"http://localhost:8080/actuator/scheduledtasks","templated":false},"mappings":{"href":"http://localhost:8080/actuator/mappings","templated":false}}}
Enable shutdown endpoint
The shutdown endpoint of the spring boot actuator is disabled by default. You can enable the shutdown endpoint with the following command. The POST method can be used to run to the shutdown command. To run the shutdown command, use the postman or curl commands.
application.properties
management.endpoint.shutdown.enabled=true
Curl command
curl -X POST http://localhost:8080/actuator/shutdown
Change the default port
To disable the default port and configure a different port for the spring boot actuator endpoints, use the following command.
application.properties
management.server.port=8081
Curl command
curl -X GET http://localhost:8081/actuator
Change the default actuator name
The following command is used to change the default actuator name in the spring boot endpoints url. The /actuator link is replaced with the configured name.
application.properties
management.endpoints.web.base-path=/monitor
Curl command
curl -X GET http://localhost:8081/monitor