Spring Boot – Actuator

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

1. Enabling Spring Boot Actuator

To enable Spring Boot actuator endpoints to your Spring Boot application, 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 application.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 application.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 application.properties file.

management.port = 9000

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

management:
   port: 9000

Now, you can create an executable JAR file, and run the Spring Boot application 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/libs directory.

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

java –jar <JARFILE> 

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

Startedc Application on Tomcat Port

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

ENDPOINTSUSAGE
/metricsTo view the application metrics such as memory used, memory free, threads, classes, system uptime etc.
/envTo view the list of Environment variables used in the application.
/beansTo view the Spring beans and its types, scopes and dependency.
/healthTo view the application health
/infoTo view the information about the Spring Boot application.
/traceTo view the list of Traces of your Rest endpoints.

Related posts:

Vấn đề Nhà sản xuất (Producer) – Người tiêu dùng (Consumer) và đồng bộ hóa các luồng trong Java
Spring Data JPA Delete and Relationships
Java Program to Implement Queue using Linked List
Object cloning trong java
A Comparison Between Spring and Spring Boot
Java Program to Generate All Subsets of a Given Set in the Lexico Graphic Order
Spring WebClient and OAuth2 Support
The Difference Between map() and flatMap()
How to Count Duplicate Elements in Arraylist
Java Program to Implement LinkedBlockingDeque API
Spring Boot - Building RESTful Web Services
Hướng dẫn Java Design Pattern – MVC
Introduction to Eclipse Collections
Hướng dẫn Java Design Pattern – Transfer Object
Spring 5 WebClient
Hướng dẫn Java Design Pattern – Singleton
Java Program to Implement Pairing Heap
Simplify the DAO with Spring and Java Generics
Spring Boot Gradle Plugin
Spring AMQP in Reactive Applications
Guide to the Volatile Keyword in Java
Spring MVC Tutorial
Java Program to Find the Vertex Connectivity of a Graph
Java Program to Convert a Decimal Number to Binary Number using Stacks
Hướng dẫn kết nối cơ sở dữ liệu với Java JDBC
Spring MVC Content Negotiation
Java Program to Implement Meldable Heap
Cài đặt và sử dụng Swagger UI
Adding Shutdown Hooks for JVM Applications
Jackson – JsonMappingException (No serializer found for class)
Loại bỏ các phần tử trùng trong một ArrayList như thế nào trong Java 8?
Java Program to Implement Sorting of Less than 100 Numbers in O(n) Complexity