Class DataSourceHealthIndicator
java.lang.Object
org.springframework.boot.actuate.health.AbstractHealthIndicator
org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator
- All Implemented Interfaces:
InitializingBean
,HealthContributor
,HealthIndicator
HealthIndicator
that tests the status of a DataSource
and optionally
runs a test query.- Since:
- 2.0.0
- Author:
- Dave Syer, Christian Dupuis, Andy Wilkinson, Stephane Nicoll, Arthur Kalimullin
-
Constructor Summary
ConstructorDescriptionCreate a newDataSourceHealthIndicator
instance.DataSourceHealthIndicator
(DataSource dataSource) Create a newDataSourceHealthIndicator
using the specifiedDataSource
.DataSourceHealthIndicator
(DataSource dataSource, String query) Create a newDataSourceHealthIndicator
using the specifiedDataSource
and validation query. -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected void
doHealthCheck
(Health.Builder builder) Actual health check logic.getQuery()
Return the validation query ornull
.void
setDataSource
(DataSource dataSource) Set theDataSource
to use.void
Set a specific validation query to use to validate a connection.Methods inherited from class org.springframework.boot.actuate.health.AbstractHealthIndicator
health
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.boot.actuate.health.HealthIndicator
getHealth
-
Constructor Details
-
DataSourceHealthIndicator
public DataSourceHealthIndicator()Create a newDataSourceHealthIndicator
instance. -
DataSourceHealthIndicator
Create a newDataSourceHealthIndicator
using the specifiedDataSource
.- Parameters:
dataSource
- the data source
-
DataSourceHealthIndicator
Create a newDataSourceHealthIndicator
using the specifiedDataSource
and validation query.- Parameters:
dataSource
- the data sourcequery
- the validation query to use (can benull
)
-
-
Method Details
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- Throws:
Exception
-
doHealthCheck
Description copied from class:AbstractHealthIndicator
Actual health check logic.- Specified by:
doHealthCheck
in classAbstractHealthIndicator
- Parameters:
builder
- theHealth.Builder
to report health status and details- Throws:
Exception
- anyException
that should create aStatus.DOWN
system status.
-
setDataSource
Set theDataSource
to use.- Parameters:
dataSource
- the data source
-
setQuery
Set a specific validation query to use to validate a connection. If none is set, a validation based onConnection.isValid(int)
is used.- Parameters:
query
- the validation query to use
-
getQuery
Return the validation query ornull
.- Returns:
- the query
-