首页 > 其他 > 详细

SSH框架JPA基于注解的多数据源

时间:2017-05-26 13:53:39      阅读:401      评论:0      收藏:0      [点我收藏+]

一、配置文件结构

  1. persistence.xml
  2. applicationContext.xml
  3. struts.xml

二、具体配置

1、persistence.xml中可配置多个persistence-unit分别不同数据库连接

 

2、applicationContext.xml中分别配置多套不同id命名的EntityManagerFactory、transaction-manager

 

3、在serviceImp中通过注解不同的@PersistenceContext,使用不同的EntityManager,如下例子:

@PersistenceContext(unitName="appPU")
private EntityManager appEntityManager;

@PersistenceContext(unitName="managerPU")
private EntityManager managerEntityManager;

 

 

 

  

SSH框架JPA基于注解的多数据源

原文:http://www.cnblogs.com/mobaids/p/6908085.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!