SpringActuatorとは
- アプリの稼働状況などの情報を返すエンドポイントを勝手に作ってくれる
使い方
- mavenの場合
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- gradleの場合
build.gradle
dependencies {
compile("org.springframework.boot:spring-boot-starter-actuator")
}
動作確認
- アプリを起動して以下にアクセス
- http://localhost:8080/health
いろいろなエンドポイント
- アクセスできるエンドポイントはいろいろある
- https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-endpoints
- 表の中でSensitiveがtrueのものはSpringSecurityの認証を通っていないと見ることができないのでそのままでは401が返る
公開設定の変更
- 認証済みでないと公開しないかどうかは設定で変更できる
- sensitiveをtrueにすると認証が必要になり、falseにすると必要なくなる
application.properties
endpoints.sensitive=false # 全エンドポイントまとめて指定する
endpoints.info.sensitive=false # 個別に指定する場合はこんな感じ
- 各エンドポイントの有効無効の設定もできるので不要なものは閉じておくとよい
- 設定のしかたはsensitiveと同じ感じ
application.properties
endpoints.enabled=false # 全エンドポイントまとめて指定する
endpoints.info.enabled=false # 個別に指定する場合はこんな感じ
- SpringSecurityとの連動を解除することもできる
application.properties
management.security.enabled=false