Backend Development
Spring Boot
Subjective
Oct 03, 2025
How do you implement custom health indicators?
Detailed Explanation
Implement HealthIndicator interface:\n\n@Component\npublic class DatabaseHealthIndicator implements HealthIndicator {\n @Autowired\n private DataSource dataSource;\n \n @Override\n public Health health() {\n try {\n Connection connection = dataSource.getConnection();\n connection.close();\n return Health.up().withDetail("database", "Available").build();\n } catch (Exception e) {\n return Health.down().withDetail("database", "Unavailable").build();\n }\n }\n}
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts