-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
The documentation for Spring Boot 3.4 now recommends the @Qualifier("xyz")
and @Bean(defaultCandidate = false)
approach to define multiple DataSources
: https://docs.spring.io/spring-boot/3.4/how-to/data-access.html#howto.data-access.configure-two-datasources
At first glance, this approach is neat because the first DataSource
is set up by auto-configuration as if there were no second DataSource
. However, the new approach has some probably unwanted side-effects that users should be made aware of.
With the previous approach (see https://docs.spring.io/spring-boot/3.3/how-to/data-access.html#howto.data-access.configure-two-datasources), the additional DataSources
would still participate in other auto-configurations such as DataSourcePoolMetricsAutoConfiguration
and DataSourceHealthContributorAutoConfiguration
. That is no longer the case with the new approach, because an additional DataSource
with defaultCandidate = false
is neither present in Map<String, DataSource>
nor is it available via ObjectProvider<DataSource>
.
I leave it to the subject matter experts to decide what should be done:
- Update documentation to mention the limitations of the new approach
- Revert documentation to previous approach
- Fix other auto-configurations that apply to a "list" of DataSources of some sort (such as
ObjectProvider<DataSource>
)—not sure if that is even possible or a good idea for that matter