If you are building a website for your business, you probably need to add some management services. Spring Boot provides several such services (such as health, audits, beans, and more) with its actuator module.
If you use Gradle, add the following dependency to your build.gradle(.kts) file:
Groovy
implementation 'org.springframework.boot:spring-boot-starter-actuator'
Kotlin
implementation("org.springframework.boot:spring-boot-starter-actuator")
If you use Maven, add the following dependency to your pom.xml file:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
Then restart the application. If you use Gradle, run the following command in a terminal window:
If you use Maven, run the following command in a terminal window:
You should see that a new set of RESTful end points has been added to the application. These are management services provided by Spring Boot. The following listing shows a typical output:
management.endpoint.configprops-org.springframework.boot.actuate.autoconfigure.context.properties.ConfigurationPropertiesReportEndpointProperties management.endpoint.env-org.springframework.boot.actuate.autoconfigure.env.EnvironmentEndpointProperties management.endpoint.health-org.springframework.boot.actuate.autoconfigure.health.HealthEndpointProperties management.endpoint.logfile-org.springframework.boot.actuate.autoconfigure.logging.LogFileWebEndpointProperties management.endpoints.jmx-org.springframework.boot.actuate.autoconfigure.endpoint.jmx.JmxEndpointProperties management.endpoints.web-org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties management.endpoints.web.cors-org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties management.health.diskspace-org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties management.info-org.springframework.boot.actuate.autoconfigure.info.InfoContributorProperties management.metrics-org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties management.metrics.export.simple-org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleProperties management.server-org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties
The actuator exposes the following:
| There is also an /actuator/shutdown endpoint, but, by default, it is visible only through JMX. To enable it as an HTTP endpoint, add management.endpoint.shutdown.enabled=true to your application.properties file and expose it with management.endpoints.web.exposure.include=health,info,shutdown. However, you probably should not enable the shutdown endpoint for a publicly available application. |
You can check the health of the application by running the following command:
$ curl http://localhost:8080/actuator/health {"status":"UP"}
You can try also to invoke shutdown through curl, to see what happens when you have not added the necessary line (shown in the preceding note) to application.properties:
$ curl -X POST http://localhost:8080/actuator/shutdown {"timestamp":1401820343710,"error":"Not Found","status":404,"message":"","path":"/actuator/shutdown"}
Because we did not enable it, the requested endpoint is not available (because the endpoint does not exist).
For more details about each of these REST endpoints and how you can tune their settings with an application.properties file (in src/main/resources), see the documentation about the endpoints.