codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🍃

Spring Boot

27 / 62 topics
26Spring Boot Actuator Basics27Using Actuator Endpoints28Creating Custom Actuator Endpoints
Tutorials/Spring Boot/Using Actuator Endpoints
🍃Spring Boot

Using Actuator Endpoints

Updated 2026-04-20
3 min read

Using Actuator Endpoints

Introduction

Spring Boot Actuator is a sub-project of Spring Boot that provides built-in endpoints that help you monitor and manage your application. These endpoints expose information about the runtime state of your application, making it easier to troubleshoot issues and understand how your application behaves in production.

In this tutorial, we will explore how to use Actuator endpoints in a Spring Boot application. We'll cover the basics of setting up Actuator, configuring endpoints, and using them to monitor and manage your application.

Prerequisites

Before you start, ensure that you have:

  • Java Development Kit (JDK) 8 or higher installed.
  • An Integrated Development Environment (IDE) like IntelliJ IDEA or Eclipse.
  • Spring Boot CLI installed (optional but recommended for quick testing).

Setting Up a Spring Boot Application

First, let's create a new Spring Boot application. You can use the Spring Initializr to bootstrap your project.

  1. Go to Spring Initializr.
  2. Select the following options:
    • Project: Maven Project
    • Language: Java
    • Spring Boot: Choose the latest stable version
  3. Add dependencies:
    • Spring Web
    • Spring Boot Actuator
  4. Click "Generate" to download the project.

Unzip the downloaded file and import it into your IDE.

Adding Actuator Endpoints

By default, Spring Boot Actuator includes several endpoints that are automatically enabled when you add the spring-boot-starter-actuator dependency. These endpoints provide information about the application's health, metrics, and other aspects.

Enabling Specific Endpoints

If you want to enable specific endpoints or customize their behavior, you can do so in your application.properties or application.yml file.

Using application.properties

# Enable all Actuator endpoints
management.endpoints.web.exposure.include=*

# Enable only specific endpoints
management.endpoints.web.exposure.include=health,info

# Change the base path for Actuator endpoints
management.endpoints.web.base-path=/actuator

Using application.yml

management:
  endpoints:
    web:
      exposure:
        include: health,info
      base-path: /actuator

Common Actuator Endpoints

Let's explore some of the most commonly used Actuator endpoints.

/health Endpoint

The /health endpoint provides information about the application's health. By default, it shows basic health status (UP or DOWN).

Example Request

curl http://localhost:8080/actuator/health

Example Response

{
  "status": "UP"
}

/info Endpoint

The /info endpoint provides general information about the application, such as build details.

Example Request

curl http://localhost:8080/actuator/info

Example Response

{
  "build": {
    "version": "1.0-SNAPSHOT",
    "artifact": "demo",
    "name": "demo"
  }
}

/metrics Endpoint

The /metrics endpoint provides various metrics about the application, such as memory usage, thread count, and more.

Example Request

curl http://localhost:8080/actuator/metrics

Example Response

{
  "names": [
    "jvm.memory.max",
    "jvm.threads.live",
    "http.server.requests"
  ]
}

/env Endpoint

The /env endpoint provides information about the application's environment variables and configuration properties.

Example Request

curl http://localhost:8080/actuator/env

Example Response

{
  "activeProfiles": [],
  "propertySources": [
    {
      "name": "server.ports",
      "properties": {
        "local.server.port": {
          "value": 8080
        }
      }
    },
    {
      "name": "applicationConfig: [classpath:/application.properties]",
      "properties": {
        "management.endpoints.web.exposure.include": {
          "value": "health,info"
        }
      }
    }
  ]
}

Customizing Actuator Endpoints

You can customize Actuator endpoints by adding your own information or modifying existing ones.

Adding Custom Health Indicators

To add custom health indicators, create a class that implements the HealthIndicator interface.

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;

@Component
public class CustomHealthIndicator implements HealthIndicator {

    @Override
    public Health health() {
        int errorCode = check(); // perform some specific health checks

        if (errorCode != 0) {
            return Health.down().withDetail("Error Code", errorCode).build();
        }
        return Health.up().build();
    }

    private int check() {
        // Implement your custom health checks here
        return 0; // Return 0 for healthy, non-zero for unhealthy
    }
}

Adding Custom Endpoints

To add a custom endpoint, create a class annotated with @Endpoint and implement the necessary methods.

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;

@Component
@Endpoint(id = "custom")
public class CustomEndpoint {

    @ReadOperation
    public String customOperation() {
        return "This is a custom endpoint response.";
    }
}

Securing Actuator Endpoints

By default, Actuator endpoints are not secured. To secure them, you can configure Spring Security.

Basic Authentication with Spring Security

First, add the Spring Security dependency to your pom.xml:

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

Then, configure security in a configuration class.

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public UserDetailsService userDetailsService() {
        UserDetails user =
            User.withDefaultPasswordEncoder()
                .username("user")
                .password("password")
                .roles("USER")
                .build();

        return new InMemoryUserDetailsManager(user);
    }

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests(authorize -> authorize
            .requestMatchers("/actuator/**").authenticated()
            .anyRequest().permitAll())
            .httpBasic(withDefaults());
        return http.build();
    }
}

Best Practices

  1. Limit Exposure: Only expose the endpoints that are necessary for monitoring and management.
  2. Secure Endpoints: Always secure Actuator endpoints to prevent unauthorized access.
  3. Customize Metrics: Customize metrics to provide more meaningful information about your application's performance.
  4. Use Health Indicators: Implement custom health indicators to monitor specific aspects of your application.

Conclusion

Spring Boot Actuator provides a powerful set of tools for monitoring and managing your Spring Boot applications. By understanding how to use and customize Actuator endpoints, you can gain valuable insights into your application's behavior and ensure it runs smoothly in production.


PreviousSpring Boot Actuator BasicsNext Creating Custom Actuator Endpoints

Recommended Gear

Spring Boot Actuator BasicsCreating Custom Actuator Endpoints