/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/java/java-503-101-054/main.java
41 строка
1 KB
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
@RestController @RequestMapping("/actuator") public class HealthController { private final DataSource dataSource; private final CacheManager cacheManager; private final ExternalService externalService; @GetMapping("/health") public ResponseEntity<HealthResponse> health() { HealthStatus dbStatus = checkDatabase(); HealthStatus cacheStatus = checkCache(); HealthStatus externalStatus = checkExternalService(); HealthStatus overall = determineOverallStatus(dbStatus, cacheStatus, externalStatus); HealthResponse response = new HealthResponse( overall, Map.of( "database", dbStatus, "cache", cacheStatus, "externalService", externalStatus ), Instant.now() ); HttpStatus status = overall == HealthStatus.UP ? HttpStatus.OK : HttpStatus.SERVICE_UNAVAILABLE; return ResponseEntity.status(status).body(response); } private HealthStatus checkDatabase() { try { try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT 1")) { return HealthStatus.UP; } } catch (Exception e) { return HealthStatus.DOWN; } } }