ビジネス用の 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.configprops-org.springframework.boot.actuate.autoconfigure.context.properties.ConfigurationPropertiesReportEndpointProperties
management.endpoint.env-org.springframework.boot.actuate.autoconfigure.env.EnvironmentEndpointProperties
management.endpoint.health-org.springframework.boot.actuate.autoconfigure.health.HealthEndpointProperties
management.endpoint.logfile-org.springframework.boot.actuate.autoconfigure.logging.LogFileWebEndpointProperties
management.endpoints.jmx-org.springframework.boot.actuate.autoconfigure.endpoint.jmx.JmxEndpointProperties
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.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties
management.info-org.springframework.boot.actuate.autoconfigure.info.InfoContributorProperties
management.metrics-org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties
management.metrics.export.simple-org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleProperties
management.server-org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties
| /actuator/shutdown エンドポイントもありますが、デフォルトでは、JMX を介してのみ表示されます。HTTP エンドポイントとして有効にするには、 management.endpoint.shutdown.enabled=true を application.properties ファイルに追加し、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":1401820343710,"error":"Not Found","status":404,"message":"","path":"/actuator/shutdown"}
有効にしなかったため、リクエストされたエンドポイントは使用できません(エンドポイントが存在しないため)。
これらの各 REST エンドポイントの詳細と、application.properties ファイル (src/main/resources 内) を使用して設定を調整する方法については、エンドポイントに関するドキュメントを参照してください。