how to setup spring data jpa with multiple datasources

青春壹個敷衍的年華 提交于 2019-12-06 07:12:16

问题


I am using Spring Data Jpa version 1.0.0.M2 here is the url: http://static.springsource.org/spring-data/data-jpa/docs/1.0.0.M2/reference/pdf/spring-data-jpa-reference.pdf

All is promised to be very simple and nice, but when it comes to two datasources it breaks down. The question is how to setup with two data sources? The JpaRepository automatically searches for EntityManager, when it finds more than two it throws exceptions.

If you have any idea with EntityManager and how to setup the spring data jpa, please post a reply. Your help is truly appreciated!!!


回答1:


<jpa:repositories base-package="org.springframework.data.jpa.repository.sample"
    entity-manager-factory-ref="secondEntityManagerFactory" />



回答2:


You can use a dynamic datasource that wrap your two datasources, as explained here:

http://blog.springsource.com/2007/01/23/dynamic-datasource-routing/




回答3:


Are you looking to use 'EntityManager-A' with Spring Data JPA and 'EntityManager-B' for another data access layer? Mark



来源:https://stackoverflow.com/questions/5870911/how-to-setup-spring-data-jpa-with-multiple-datasources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!