欢迎访问我的个人网站==》 jiashubing.cn

JPA多数源的一种方式

  JPA设置多数据源有很多种方法,有一种古老而有效的方法,可以让不同目录下建的DAO到不同的数据源,只在xml里设置一次就可以,其核心逻辑是:<jpa:repositories>  标签

 

<!-- 基本数据源定义 -->
<jpa:repositories base-package="cn.jiashubing,com.jiashubing"
    transaction-manager-ref="transactionManager"
    entity-manager-factory-ref="entityManagerFactory"
                  repository-impl-postfix="Impl"/>

<!-- 日志数据源定义 -->
<jpa:repositories base-package="cn.jiashubing.log,com.jiashubing.log"
    transaction-manager-ref="transactionManager_log"
    entity-manager-factory-ref="entityManagerFactory_log"
    repository-impl-postfix="Impl" />

 

base-package 指向不同的路径

transactionManager、entityManagerFactory、transactionManager_log、entityManagerFactory_log 的定义参考网上资料

 

原创文章,欢迎转载,转载请注明出处!

posted @ 2020-09-10 20:18  贾树丙  阅读(337)  评论(0编辑  收藏  举报