How to Push to a GitHub Repository in IntelliJ
Spring Boot Actuator provides a wide range of features to monitor and manage your application when it's deployed in a production environment. These features can be accessed via HTTP endpoints or JMX, and they automatically enable capabilities such as auditing, health checks, and metrics collection in your application.
Actuator is essential in cloud-native and microservice architectures, allowing real-time monitoring of application status, metrics, and traffic data. In particular, the /actuator/health endpoint offers a basic mechanism to check if the application is running properly, making it crucial for integration with load balancers, Kubernetes, and other orchestration tools.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
application.yamlmanagement:
endpoints:
web:
exposure:
include: health,info # expose only selected endpoints
endpoint:
health:
show-details: always # 'always' for dev, 'never' for production
If you don't specify
management.server.port, actuator endpoints will run on the main application port (e.g., 8080).
management:
endpoint:
health:
probes:
enabled: true
health:
livenessState:
enabled: true
readinessState:
enabled: true
From Spring Boot 2.3, Actuator automatically provides /actuator/health/liveness and /actuator/health/readiness endpoints.
/actuator/health, update your Spring Security config:http
.authorizeHttpRequests(auth -> auth
.requestMatchers(
"/api/v1/public/", // public API
"/actuator/**", // allow actuator access
).permitAll()
.requestMatchers(
"/api/v1/users/**",
).authenticated()
.anyRequest().authenticated()
Note: If permitAll() is not specified, the endpoint will require authentication and result in a 403 Forbidden error.
Spring Boot Actuator exposes several endpoints, each serving specific monitoring or management purposes. Common endpoints include:
| Endpoint | Purpose |
|---|---|
/actuator/health |
Shows application health status |
/actuator/health/liveness |
Checks if JVM is alive (K8s liveness probe) |
/actuator/health/readiness |
Checks if app is ready for traffic (K8s readiness probe) |
/actuator/info |
Displays application info |
/actuator/metrics |
Exposes performance and system metrics |
/actuator/env |
Displays environment properties |
/actuator/loggers |
Shows and modifies logger configuration |
/actuator/beans |
Lists all Spring beans |
/actuator/prometheus |
For Prometheus metrics scraping (requires Micrometer) |
Endpoints are exposed under the /actuator base path by default.
/actuator/healthThe /actuator/health endpoint is the simplest and most essential way to confirm your application is running correctly. It can show not only the overall status but also details such as database connections, disk space, and other dependencies.
Example:
$ curl http://your-domain.com:port/actuator/health
{
"status": "UP"
}
/actuator/health is used to periodically verify application health.Since Spring Boot 2.3, Actuator supports Kubernetes-native probes, enhancing cloud-native operations.
These are exposed as:
/actuator/health/liveness/actuator/health/readinessExample configuration for Kubernetes:
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
/actuator/health returns DOWN or OUT_OF_SERVICE, you can integrate with Datadog, Zabbix, Opsgenie, etc., to send alerts via Slack, email, or SMS./actuator/health returns 200 OK with "status": "UP", the deployment is considered successful; otherwise, the pipeline can trigger an automatic rollback.permitAll not set)o.s.s.w.a.Http403ForbiddenEntryPoint : Pre-authenticated entry point called. Rejecting access
/actuator/** in your Spring Security configuration.Causes:
application.yaml.Log example:
org.springframework.web.servlet.resource.NoResourceFoundException: No static resource actuator/health.
Solution:
/actuator base path.
Comments
Post a Comment