문제

I am playing with spring-boot and spring-boot-data-jpa. I need that @Entity class A {...} uses hsqlDatasource and @Entity class B {...} use mssqlDatasource. How can I achieve that?

I would like to do something like this:

@Repository
@UseDatasource("hsql")
interface A extends CrudRepository....
도움이 되었습니까?

해결책

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top