Spring Data supports this pattern through @EnableJpaRepositories(entityManagerFactoryRef=...)
. To make it work with Spring Boot you could create your 2 DataSources
, mark one of them @Primary
and it will be used by the auto-configured entityManagerFactory
bean. Then you add another and refer to them both individually in your 2 @EnableJpaRepositories
annotations.
I suppose you could even create a custom annotation for each of the two repository types and use it in @EnableJpaRepositories(includeFilters=...)
, but if I were you I would get it working with a package scan first (i.e. just put the repositries for the 2 data source targets in different packages).