English 中文(简体)
Spring Boot Tutorial

Spring Boot Resources

Selected Reading

Spring Boot - Actuator
  • 时间:2024-11-03

Spring Boot - Actuator


Previous Page Next Page  

Spring Boot Actuator provides secured endpoints for monitoring and managing your Spring Boot apppcation. By default, all actuator endpoints are secured. In this chapter, you will learn in detail about how to enable Spring Boot actuator to your apppcation.

Enabpng Spring Boot Actuator

To enable Spring Boot actuator endpoints to your Spring Boot apppcation, we need to add the Spring Boot Starter actuator dependency in our build configuration file.

Maven users can add the below dependency in your pom.xml file.

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Gradle users can add the below dependency in your build.gradle file.

compile group:  org.springframework.boot , name:  spring-boot-starter-actuator 

In the apppcation.properties file, we need to disable the security for actuator endpoints.

management.security.enabled = false

YAML file users can add the following property in your apppcation.yml file.

management:
   security:
      enabled: false

If you want to use the separate port number for accessing the Spring boot actutator endpoints add the management port number in apppcation.properties file.

management.port = 9000

YAML file users can add the following property in your apppcation.yml file.

management:
   port: 9000

Now, you can create an executable JAR file, and run the Spring Boot apppcation by using the following Maven or Gradle commands.

For Maven, you can use the following command −

mvn clean install

After “BUILD SUCCESS”, you can find the JAR file under the target directory.

For Gradle, you can use the following command −

gradle clean build

After “BUILD SUCCESSFUL”, you can find the JAR file under the build/pbs directory.

Now, you can run the JAR file by using the following command −

java –jar <JARFILE> 

Now, the apppcation has started on the Tomcat port 8080. Note that if you specified the management port number, then same apppcation is running on two different port numbers.

Startedc Apppcation on Tomcat Port

Some important Spring Boot Actuator endpoints are given below. You can enter them in your web browser and monitor your apppcation behavior.

ENDPOINTS USAGE
/metrics To view the apppcation metrics such as memory used, memory free, threads, classes, system uptime etc.
/env To view the pst of Environment variables used in the apppcation.
/beans To view the Spring beans and its types, scopes and dependency.
/health To view the apppcation health
/info To view the information about the Spring Boot apppcation.
/trace To view the pst of Traces of your Rest endpoints.
Advertisements