-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/com/helpmeCookies/global/infra/CustomDatabaseHealthIndicator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.helpmeCookies.global.infra; | ||
|
||
import com.helpmeCookies.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.HealthIndicator; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CustomDatabaseHealthIndicator implements HealthIndicator { | ||
|
||
private final UserRepository userRepository; | ||
@Override | ||
public Health health() { | ||
try { | ||
// 테이블이 존재하는지 확인하는 쿼리 (Users 테이블 사용) | ||
long count = userRepository.count(); | ||
// 테이블 존재 시 0 이상을 반환 | ||
return Health.up().withDetail("Users table exists, count: ", count).build(); | ||
} catch (Exception e) { | ||
// 테이블이 없거나 데이터베이스 연결에 문제가 있는 경우 | ||
return Health.down(e).withDetail("Users table", "Table missing or database issue") | ||
.build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters