How to enable Actuator in Spring Boot?

Spring Boot Actuator can be enabled by adding the Actuator starter dependency to the project. Once enabled, it provides production-ready endpoints that help monitor, manage, and inspect the application's health, metrics, configuration, and runtime behavior.

Key Points: • Spring Boot Actuator provides monitoring and management capabilities. • It is enabled by adding the spring-boot-starter-actuator dependency. • Actuator endpoints can be exposed through HTTP or JMX. • Common endpoints include health, metrics, info, beans, and environment details. • Endpoint visibility can be controlled through application properties.

Why Do We Need Actuator?

In production environments, developers and administrators often need to know:

• Is the application running? • Is the database connected? • How much memory is being used? • How many requests are being processed? • What beans are loaded?

Actuator provides this information without writing custom monitoring code.

Step 1: Add Actuator Dependency

Maven Dependency:

Code Example:

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

After adding the dependency, Spring Boot automatically configures Actuator.

Step 2: Expose Actuator Endpoints

By default, only a few endpoints are exposed.

application.properties

Code Example:

management.endpoints.web.exposure.include=*

This exposes all available Actuator endpoints.

To expose specific endpoints only:

Code Example:

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

This is the recommended approach for production systems.

Step 3: Access Endpoints

After starting the application:

Health Endpoint:

http://localhost:8080/actuator/health

Info Endpoint:

http://localhost:8080/actuator/info

Metrics Endpoint:

http://localhost:8080/actuator/metrics

Beans Endpoint:

http://localhost:8080/actuator/beans

Environment Endpoint:

http://localhost:8080/actuator/env

Example Response

Health Endpoint:

{ "status": "UP" }

This indicates that the application is running successfully.

How It Works Internally

Application Starts | Actuator Dependency Detected | Auto-Configuration Applied | Management Endpoints Created | Endpoints Exposed | Monitoring Available

Spring Boot automatically registers the Actuator endpoints during startup.

Commonly Used Actuator Endpoints

• /actuator/health • /actuator/info • /actuator/metrics • /actuator/env • /actuator/beans • /actuator/mappings • /actuator/loggers • /actuator/threaddump

These endpoints provide valuable runtime information.

Example: Suppose an Employee Management System is deployed to production.

Operations Team wants to verify:

• Application status • JVM memory usage • Active beans • Request metrics

Instead of writing custom APIs, they can use:

/actuator/health

/actuator/metrics

/actuator/beans

provided by Spring Boot Actuator.

Security Consideration

In production:

Avoid exposing all endpoints publicly.

Instead:

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

Sensitive endpoints such as:

• env • beans • mappings

should usually be protected with Spring Security.

Benefits of Actuator

• Production monitoring • Health checks • Application metrics • Runtime diagnostics • Easier troubleshooting • Integration with monitoring tools

Real-World Example

In a microservices architecture, Kubernetes often uses:

/actuator/health

to determine whether a service is healthy and ready to receive traffic.

Monitoring tools such as:

• Prometheus • Grafana • Datadog

can collect metrics from Actuator endpoints for real-time monitoring.

Interview Tip: A concise interview answer is:

"To enable Actuator in Spring Boot, add the spring-boot-starter-actuator dependency. Spring Boot automatically configures management endpoints such as health, metrics, and info. We can control which endpoints are exposed using the management.endpoints.web.exposure.include property in application.properties or application.yml."