Überwachung mit Spring Boot Actuator
Nutzen Sie Spring-Boot-Actuator-Endpunkte, um Ihre Anwendung in der Produktion zu überwachen, zu verwalten und zu untersuchen.
Überwachung mit Spring Boot Actuator ist eine kostenlose Spring Boot 4 Complete Guide-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Spring Boot 4 Complete Guide-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Spring Boot 4 Complete Guide-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Meet Spring Boot Actuator
Spring Boot Actuator is a powerful tool that helps you monitor and manage your application when it's running in production. Think of it as your app's built-in dashboard!
It provides production-ready features without requiring you to write much code.
- Monitoring: Check health, metrics, and environment details.
- Management: Log levels, shutdown, refresh context.
- Insight: Understand your app's internal workings.
Include Actuator in Your Project
To use Actuator, you just need to add its starter dependency to your project. This brings in all the necessary libraries.
For Maven, add this to your pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>Discover Actuator's Endpoints
Once Actuator is added, your application automatically exposes several "endpoints". These are HTTP URLs that provide specific information about your running app.
Some default endpoints include:
/actuator/health: Shows application health status./actuator/info: Displays general application information./actuator/metrics: Provides detailed metrics (CPU, memory, etc.).
By default, only /health and /info are exposed via web.
Run & Access Actuator
Let's create a simple Spring Boot app with Actuator. After running it, you can access the default endpoints in your browser or with a tool like curl.
Try running this and then navigate to http://localhost:8080/actuator/health.
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ActuatorDemoApplication {
public static void main(String[] args) {
SpringApplication.run(ActuatorDemoApplication.class, args);
}
}Deep Dive: The /health Endpoint
The /actuator/health endpoint is crucial for understanding your application's operational status. It aggregates information from various "health indicators".
- DiskSpace: Checks available disk space.
- DataSource: Verifies database connectivity (if configured).
- Liveness/Readiness: For Kubernetes deployments (newer versions).
It typically returns {"status": "UP"} if everything is fine, or details if something is down.
Custom Info with /info
The /actuator/info endpoint provides general information about your application. By default, it's empty, but you can easily populate it with useful details.
Add custom properties to your application.properties or application.yml:
info.app.name=MyActuatorApp
info.app.version=1.0.0
info.app.description=A demo for CoddyKitConfigure & Expose More Endpoints
By default, only /health and /info are exposed over the web. You can expose more endpoints like /beans (list all Spring beans) or /env (environment properties).
To expose all endpoints, add this to application.properties:
management.endpoints.web.exposure.include=*Monitor Performance with /metrics
The /actuator/metrics endpoint is invaluable for performance monitoring. It exposes various metrics about your application, JVM, and system.
Examples of metrics:
jvm.memory.used: Current JVM memory usage.system.cpu.usage: System CPU load.http.server.requests: Details about incoming HTTP requests.
You can query specific metrics like /actuator/metrics/jvm.memory.used for detailed data.
Build Your Own Health Checks
You can create custom health indicators to check the status of specific parts of your application, like an external service dependency or a custom cache.
Implement the HealthIndicator interface:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;
@SpringBootApplication
public class CustomHealthApp {
public static void main(String[] args) {
SpringApplication.run(CustomHealthApp.class, args);
}
}
@Component
class MyCustomHealthIndicator implements HealthIndicator {
@Override
public Health health() {
// Simulate checking an external service
boolean serviceIsUp = Math.random() > 0.5; // Randomly up or down
if (serviceIsUp) {
return Health.up().withDetail("myServiceStatus", "OK").build();
} else {
return Health.down().withDetail("myServiceStatus", "Failed").build();
}
}
}Quick Check: Actuator Endpoints
Which of the following Actuator endpoints are exposed by default over the web in a basic Spring Boot application with the Actuator dependency?
Actuator: Your App's Best Friend
Congratulations! You've learned how Spring Boot Actuator transforms your application into a production-ready, observable service.
- It provides crucial insights into your app's health and performance.
- You can easily add it with a single dependency.
- Default endpoints like
/healthand/infoare automatically available. - You can expose more endpoints and even create custom health checks.
Actuator is a must-have for any serious Spring Boot application!
Häufig gestellte Fragen
Ist die Lektion „Überwachung mit Spring Boot Actuator“ kostenlos?
Ja — der vollständige Text von „Überwachung mit Spring Boot Actuator“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Spring Boot 4 Complete Guide-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Spring Boot 4 Complete Guide-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Überwachung mit Spring Boot Actuator“?
Nutzen Sie Spring-Boot-Actuator-Endpunkte, um Ihre Anwendung in der Produktion zu überwachen, zu verwalten und zu untersuchen. Du übst Spring Boot 4 Complete Guide mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Spring Boot 4 Complete Guide zu starten?
Keine Vorkenntnisse erforderlich. Spring Boot 4 Complete Guide auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „Überwachung mit Spring Boot Actuator“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Spring Boot 4 Complete Guide-Lektion Code schreiben und ausführen?
Ja. Jede Spring Boot 4 Complete Guide-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Spring-Boot-Anwendungen mit Docker containerisieren
- Überwachung mit Spring Boot Actuator
- Strategien für Cloud-Deployments
- CI/CD-Pipelines für Spring Boot erstellen