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 的定义参考网上资料

 

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-02-08
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-20
  • 2021-12-06
  • 2021-05-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-15
相关资源
相似解决方案