ビジネス用の Web サイトを構築する場合、管理サービスを追加する必要があるかもしれません。Spring Boot は、アクチュエーターモジュールを使用して、そのようなサービス(ヘルス、監査、Bean など)をいくつか提供しています。
Gradle を使用する場合は、build.gradle(.kts) ファイルに次の依存関係を追加します。
Groovy
implementation 'org.springframework.boot:spring-boot-starter-actuator'
Kotlin
implementation("org.springframework.boot:spring-boot-starter-actuator")
Maven を使用する場合は、pom.xml ファイルに次の依存関係を追加します。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
アプリケーションを再起動します。Gradle を使用している場合は、ターミナルウィンドウで次のコマンドを実行してください。
Maven を使用する場合は、ターミナルウィンドウで次のコマンドを実行します。
アプリケーションに新しい RESTful エンドポイントが追加されているはずです。これらは Spring Boot が提供する管理サービスです。以下に典型的な出力を示します。
management.endpoint.health-org.springframework.boot.health.autoconfigure.actuate.endpoint.HealthEndpointProperties
management.endpoints.web-org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties
management.endpoints.web.cors-org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties
management.health.diskspace-org.springframework.boot.health.autoconfigure.application.DiskSpaceHealthIndicatorProperties
management.health.ssl-org.springframework.boot.health.autoconfigure.application.SslHealthIndicatorProperties
management.info-org.springframework.boot.actuate.autoconfigure.info.InfoContributorProperties
management.metrics-org.springframework.boot.micrometer.metrics.autoconfigure.MetricsProperties
management.observations-org.springframework.boot.micrometer.observation.autoconfigure.ObservationProperties
management.simple.metrics.export-org.springframework.boot.micrometer.metrics.autoconfigure.export.simple.SimpleProperties
| /actuator/shutdown エンドポイントも存在しますが、デフォルトでは無効になっています。公開するには、application.properties ファイルに management.endpoint.shutdown.access=unrestricted を追加し、management.endpoints.web.exposure.include=health,info,shutdown で公開してください。ただし、公開アプリケーションではシャットダウンエンドポイントを有効にしない方が良いでしょう。 |
次のコマンドを実行して、アプリケーションの正常性を確認できます。
$ curl http://localhost:8080/actuator/health
{"status":"UP"}
また、curl を使用してシャットダウンを呼び出して、application.properties に必要な行(前の注を参照)を追加していない場合に何が起こるかを確認することもできます。
$ curl -X POST http://localhost:8080/actuator/shutdown
{"timestamp":"2026-02-06T08:13:01.514Z","status":404,"error":"Not Found","path":"/actuator/shutdown"}
有効にしなかったため、リクエストされたエンドポイントは使用できません(エンドポイントが存在しないため)。
これらの各 REST エンドポイントの詳細と、application.properties ファイル (src/main/resources 内) を使用して設定を調整する方法については、エンドポイントに関するドキュメントを参照してください。