TestDatabaseAutoConfiguration in the getDataSourceBeanDefinition method explicitly only finds for the primary data source to replace it with an embedded datasource.

When running a Spring Boot app with multiple datasources, you might expect all of them to be replaced with embedded datasources. It would be helpful if a message was logged for all non-primary data sources found explaining that they were not replaced because only replacing the primary data source is supported, possible with a reference to documentation explaining what the recommended approach is in the multiple-datasource scenario.

Also, the Javadoc for @AutoConfigureTestDatabase is somewhat misleading here:

 /**
 * Replace any DataSource bean (auto-configured or manually defined).
 */
ANY,

Actually, not "any" data source is replaced; only a single data source annotated as (or implicitly) @Primary.

Happy to submit pull requests for all of the above.

Comment From: wilkinsona

Thanks for raising this. Auto-configuration of multiple DataSources is being tracked by https://github.com/spring-projects/spring-boot/issues/15732. I expect some corresponding improvements to be made to TestDatabaseAutoConfiguration as part of that. In the meantime, I think it would certainly be worthwhile clarifying exactly what "any" means. "(auto-configured or manually defined)" was an attempt to do that, but I agree that it's not clear that it means the context's only or primary DataSource bean, irrespective of whether it was manually defined or auto-configured.