Skip to content

Application does not start anymore with only AbstractRoutingDataSource beans #18661

@tokuhirom

Description

@tokuhirom

DataSourceHealthContributorAutoConfiguration loads all DataSources. And monitoring all data sources with an actuator.

It ignores AbstractRoutingDataSource... So it's a good implementation since the destination of AbstractRoutingDataSource may change.

@Bean
@ConditionalOnMissingBean(name = { "dbHealthIndicator", "dbHealthContributor" })
public HealthContributor dbHealthContributor(Map<String, DataSource> dataSources) {
return createContributor(filterDataSources(dataSources));
}
private Map<String, DataSource> filterDataSources(Map<String, DataSource> candidates) {
if (candidates == null) {
return null;
}
Map<String, DataSource> dataSources = new LinkedHashMap<>();
candidates.forEach((name, dataSource) -> {
if (!(dataSource instanceof AbstractRoutingDataSource)) {
dataSources.put(name, dataSource);
}
});
return dataSources;
}

But createContributor throws an exception when the argument is empty.

protected final C createContributor(Map<String, B> beans) {
Assert.notEmpty(beans, "Beans must not be empty");
if (beans.size() == 1) {
return createIndicator(beans.values().iterator().next());
}
return createComposite(beans);
}

As a result, if the module have only AbstractRoutingDataSources, boot application can't run.

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions