Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Spring Boot Starters
3.
Spring Boot Starter Actuator
4.
Features of Spring Boot Actuator
5.
Spring Boot Actuator Endpoints
6.
FAQs
7.
Key Takeaways
Last Updated: Mar 27, 2024

Spring Boot Starter Actuator

Author Rajat Agrawal
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

Spring Boot Starters are the dependency descriptor that can be included in the project. Spring Boot provides several Starters that can be used to add all the dependencies required for a project.

Spring Boot Starter Actuator is one of the starters provided by Spring Boot.

Let’s understand the Spring Boot Starters with examples.

Spring Boot Starters

As discussed in the introduction section, Spring Boot Starters are the dependency descriptor included in the project.

Spring Boot Starters can be added to the pom.xml file of our project as per the project's requirement. You need to add the starters to the pom.xml file, and those starters will automatically provide all the required dependencies.

For example, if we want to create a web application, we need to add spring-boot-starter-web in the pom.xml file. This spring-boot-starter-web itself contains a pom.xml in which all the required dependencies for a web application project are present.

The below starter for spring-boot-starter-web can be added to pom.xml to create a web application:

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

 

Only the above starter is required to add to the pom.xml file, and this starter will automatically provide all the web-related dependencies.

Spring Boot provides several Starters that can be used to add all the dependencies required for a project. Let’s now discuss the spring-boot-starter-actuator in depth.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Spring Boot Starter Actuator

Spring Boot Actuator provides secured endpoints for monitoring and managing the Spring Boot application. By default, all actuator endpoints are secured. It provides several additional features that help us monitor and manage the Spring Boot application. It contains the actuator endpoints. 

With the help of actuator endpoints such as HTTP and JMX,  we can manage and monitor the spring boot applications.

To enable the production-ready features into your application, you can use Starter Actuator.

To enable Spring Boot Actuator into our Spring Boot application, we need to add spring-boot-starter-actuator dependency in the pom.xml file. 

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

 

You can see we have added this dependency into our pom.xml in the following picture:

Let’s now discuss some of the features of the Spring Boot Actuator.

Features of Spring Boot Actuator

There are three main features of the Actuator:

1.) Endpoints

2.) Metrics

3.) Audit

Let’s learn about these features.

Endpoints: The actuator endpoints will allow us to monitor and interact with the application. Spring Boot provides several built-in endpoints. We can also create our own endpoint. Most of the applications choose HTTP, where the Id of the endpoint, along with the prefix of /actuator, is mapped to a URL.

For example, the /env endpoint is used to expose properties from Spring's ConfigurableEnvironment. By default, the actuator is mapped to it like this /actuator/env.

Metrics: Spring Boot Actuator provides metrics by integrating with the micrometer. The micrometer is integrated into Spring Boot. A micrometer is a vendor-neutral metrics facade, meaning metrics can be collected in one way but revealed in the format required by many different monitoring systems.

Audit: Spring Boot provides an audit framework that produces events to an AuditEventRepository. It involuntarily publishes the authentication events if spring-security is in execution.

Spring Boot Actuator Endpoints

The actuator endpoints allow us to monitor and interact with the spring boot application. Spring Boot provides several built-in endpoints. We can also create our own endpoint.

Some of the most widely used endpoints are mentioned below:

1.) /metric: It is used to view the application metrics such as memory used, memory-free, threads, system uptime, etc.

2.) /env: It is used to view the list of Environment variables used in the application.

3.) /health: It is used to show the health of the application.

4.) /info: It is used to view the information about the Spring Boot application.

5.) /trace: It is used to view the list of Traces of your rest endpoints.

6.) /beans: It is used to show the complete list of all the Spring beans in your application.

In this blog, we will fetch two endpoints to show how the endpoints work and have that idea; you can easily implement other endpoints.

Before you start fetching the endpoints make sure that you have injected the spring-boot-starter-actuator dependency into your pom.xml file.

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

 

Note: All actuators other than /health are disabled by default for security purposes. You can use the management.endpoints.web.exposure.include property to enable the actuators.

Set management.endpoints.web.exposure.include = * in the application.properties file. This will enable all the actuator endpoints, even the most sensitive endpoints also (e.g /env, /beans, etc.).


Run the <Application>.java file, open the browser, and invoke the URL http://localhost:8080/actuatorIt will return the following page:


Fetching the /health Endpoint: 

/health endpoint is used to show the health of the application.

Go to the browser and invoke the URL http://localhost:8080/actuator/health. It will return the following page:

It shows the status UP, which means the application is healthy and running without any problem.

Fetching the /beans Endpoint:

/beans is used to show the complete list of all the Spring beans in your application.

Go to the browser and invoke the URL http://localhost:8080/actuator/beans. It will return the following page:

FAQs

  1. What is a spring boot actuator?
    Spring Boot Actuators are the starters that provide secure endpoints for monitoring and managing the Spring Boot application.
     
  2. What is the use of /health endpoint?
    The /health endpoint is used to show the health of the application. If It shows the status UP, It means the application is healthy and running without any problem.
     
  3. What is the use of /shutdown endpoint?
    The /shutdown endpoint is used to allow the application to be gracefully shut down.

Key Takeaways

In this blog, we have learned about the Spring Boot Starter Actuator, the features of the spring boot actuator, and the different endpoints it provides.

Recommended Readings:

You can also consider our Spring Boot Course to give your career an edge over others.

Happy Learning!!

Previous article
Spring Data JPA
Next article
Spring Boot Starter Test
Live masterclass