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

28 / 62 topics
26Spring Boot Actuator Basics27Using Actuator Endpoints28Creating Custom Actuator Endpoints
Tutorials/Spring Boot/Creating Custom Actuator Endpoints
🍃Spring Boot

Creating Custom Actuator Endpoints

Updated 2026-04-20
4 min read

Creating Custom Actuator Endpoints

Introduction

Spring Boot Actuator is a powerful tool that provides production-ready features to help you monitor and manage your application. It includes a set of endpoints that expose operational information about the running application, such as health status, metrics, and more. However, sometimes you need to create custom endpoints tailored to your specific requirements.

In this tutorial, we will walk through the process of creating custom Actuator endpoints in Spring Boot. We'll cover the necessary steps, best practices, and provide real-world code examples to help you get started.

Prerequisites

Before diving into the implementation, ensure that you have the following prerequisites:

  • Basic understanding of Spring Boot.
  • Java Development Kit (JDK) 8 or higher installed.
  • An Integrated Development Environment (IDE) like IntelliJ IDEA or Eclipse.
  • Maven or Gradle for building and managing dependencies.

Setting Up a Spring Boot Project

First, let's set up a basic Spring Boot project. You can use Spring Initializr to bootstrap your project quickly.

  1. Go to Spring Initializr.

  2. Configure your project with the following settings:

    • Project: Maven Project
    • Language: Java
    • Spring Boot: Choose the latest stable version.
    • Project Metadata:
      • Group: com.example
      • Artifact: custom-actuator-endpoints
      • Name: Custom Actuator Endpoints
      • Description: Demo project for custom actuator endpoints
      • Package name: com.example.customactuatorendpoints
    • Packaging: Jar
    • Java: 8 or higher
  3. Add the following dependencies:

    • Spring Web
    • Spring Boot Actuator
  4. Click on "Generate" to download the project zip file.

  5. Extract the zip file and import it into your IDE.

Creating a Custom Actuator Endpoint

Now, let's create a custom Actuator endpoint that exposes some operational information about our application.

Step 1: Create the Endpoint Class

Create a new Java class in the com.example.customactuatorendpoints package. Let's call it CustomEndpoint.

package com.example.customactuatorendpoints;

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 customEndpoint() {
        return "This is a custom Actuator endpoint!";
    }
}

Explanation

  • @Component: This annotation marks the CustomEndpoint class as a Spring component, making it eligible for auto-detection when using component scanning.
  • @Endpoint(id = "custom"): This annotation defines the endpoint with the ID custom. The endpoint will be accessible at /actuator/custom.
  • @ReadOperation: This annotation indicates that the method should handle read requests. You can also use @WriteOperation for write operations.

Step 2: Configure Actuator

Ensure that Actuator is enabled in your Spring Boot application. By default, it should be enabled if you added the Spring Boot Actuator dependency. However, you can explicitly enable it by adding the following property to your application.properties file:

management.endpoints.web.exposure.include=custom,health,info

This configuration exposes the custom endpoint along with the default health and info endpoints.

Step 3: Run the Application

Run your Spring Boot application. You can do this by executing the main class or using the following Maven command:

mvn spring-boot:run

Once the application is running, you can access your custom endpoint at http://localhost:8080/actuator/custom. You should see the response "This is a custom Actuator endpoint!".

Advanced Customization

Returning JSON Data

You can return structured data from your endpoint by using a map or a custom class. Let's modify our endpoint to return some JSON data.

package com.example.customactuatorendpoints;

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

import java.util.HashMap;
import java.util.Map;

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

    @ReadOperation
    public Map<String, Object> customEndpoint() {
        Map<String, Object> response = new HashMap<>();
        response.put("message", "This is a custom Actuator endpoint!");
        response.put("timestamp", System.currentTimeMillis());
        return response;
    }
}

Now, when you access the /actuator/custom endpoint, you will receive JSON data:

{
  "message": "This is a custom Actuator endpoint!",
  "timestamp": 1633072800000
}

Conditional Exposure

You can conditionally expose your endpoints based on certain conditions. For example, you might want to expose the endpoint only in production.

package com.example.customactuatorendpoints;

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

@Component
@Endpoint(id = "custom")
@ConditionalOnProperty(name = "management.endpoints.web.exposure.include", havingValue = "custom")
public class CustomEndpoint {

    @ReadOperation
    public String customEndpoint() {
        return "This is a custom Actuator endpoint!";
    }
}

In this example, the CustomEndpoint will only be exposed if the property management.endpoints.web.exposure.include is set to custom.

Best Practices

  1. Security: Ensure that your custom endpoints are secured appropriately. By default, Actuator endpoints are protected by Spring Security if it's present in your application.
  2. Documentation: Document your custom endpoints clearly so that other developers understand their purpose and usage.
  3. Performance: Be mindful of the performance implications of your endpoints, especially if they involve complex operations or access to sensitive data.
  4. Testing: Write unit tests for your custom endpoints to ensure they behave as expected.

Conclusion

In this tutorial, we have learned how to create custom Actuator endpoints in Spring Boot. We covered the basics of defining and exposing endpoints, returning JSON data, and applying conditional exposure. By following these steps and best practices, you can effectively monitor and manage your application with custom Actuator endpoints tailored to your specific needs.

Feel free to explore more advanced features of Spring Boot Actuator and customize your endpoints further based on your application's requirements.


PreviousUsing Actuator EndpointsNext Asynchronous Programming in Spring Boot

Recommended Gear

Using Actuator EndpointsAsynchronous Programming in Spring Boot