Spring Boot makes it really easy to include a single, default data source. It auto-configures all the required components (TransactionManager, EntityManagerFactory, JpaVendorAdapter, Datasource...).
The existing @EntityScan is great in that it it allows you to effectively loosely-couple your persistence implementation. Without it, you'd need to hard-code your packagesToScan.
My issue comes when you want to use multiple datasources. It's not that hard to create the beans manually. However, it does have one unfortunate side-effect; it means that we can't use @EntityScan. So we're back to hard-coding the packagesToScan parameter.
Would it be possible to do the following:
Add an annotation for auto-configuring multiple data sources
The annotation should trigger behaviour exactly like Spring Boot does with a single data source, but for multiple data sources.
Would create the following beans:
The @EntityScan could then be enhanced to only configure the primary EntityManager (which should help make this change backwards-compatible with existing code).
An additional parameter: "entityManagerFactoryRef" could be added to specify which EntityManagerFactory to use. E.g.
..it'd also be nice if @EnableJpaRepositories was @Repeatable so we don't have to create separate config files for the red and blue datasources, but it's a minor issue.