Restore AbstractRoutingDataSource health support
Update `DataSourceHealthContributorAutoConfiguration` so that any
`AbstractRoutingDataSource` beans are still included in the overall
health. Prior to this commit, a regression in Spring Boot 2.2 meant
that if a single routing bean was found an `IllegalArgumentException`
would be thrown.
In Spring Boot 2.1 all `AbstractRoutingDataSource` would be filtered
from the results, but if no results existed the following was returned:
"details": {
"db": {
"status": "UNKNOWN"
},
In Spring Boot 2.2 we now always include routing datasource beans, even
if other non-routing database beans are found. The health details
includes `"routing" : true` to help users disambiguate any results.
Fixes gh-18661
This commit is contained in:
@@ -21,6 +21,7 @@ import javax.sql.DataSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
|
||||
import org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration.RoutingDataSourceHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.CompositeHealthContributor;
|
||||
import org.springframework.boot.actuate.health.NamedContributor;
|
||||
import org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator;
|
||||
@@ -71,10 +72,20 @@ class DataSourceHealthContributorAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void runShouldFilterRoutingDataSource() {
|
||||
void runWithRoutingAndEmbeddedDataSourceShouldFilterRoutingDataSource() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class, RoutingDatasourceConfig.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(DataSourceHealthIndicator.class)
|
||||
.doesNotHaveBean(CompositeHealthContributor.class));
|
||||
.run((context) -> {
|
||||
CompositeHealthContributor composite = context.getBean(CompositeHealthContributor.class);
|
||||
assertThat(composite.getContributor("dataSource")).isInstanceOf(DataSourceHealthIndicator.class);
|
||||
assertThat(composite.getContributor("routingDataSource"))
|
||||
.isInstanceOf(RoutingDataSourceHealthIndicator.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWithOnlyRoutingDataSourceShouldFilterRoutingDataSource() {
|
||||
this.contextRunner.withUserConfiguration(RoutingDatasourceConfig.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(RoutingDataSourceHealthIndicator.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user