我必須創建這樣一個PostgreSQL健康指標:春季啓動驅動器健康端點
@Component
public class PostgresHealthIndicator extends AbstractHealthIndicator {
@Autowired
DataSource postgresDataSource;
public DataSourceHealthIndicator dbHealthIndicator() {
DataSourceHealthIndicator indicator = new DataSourceHealthIndicator(postgresDataSource);
return indicator;
}
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
Health h = dbHealthIndicator().health();
Status status = h.getStatus();
if (status != null && "DOWN".equals(status.getCode())) {
builder.down();
} else {
builder.up();
}
}
}
在我Application.java我掃描這個包這個組件:
@ComponentScan({"com.bp.health"})
在我的應用程序。屬性我有以下設置:
endpoints.health.sensitive=false
endpoints.health.id=health
endpoints.health.enabled=true
當我打{url}/health我看到:
{ 「地位」: 「DOWN」}
什麼,我需要做的就是自定義的健康指示器顯示?