jpa 连接多个mysql 数据库_Spring+jpa连接多个数据库

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

transaction-type="RESOURCE_LOCAL">

org.apache.openjpa.persistence.PersistenceProviderImpl

cn.wiztek.hprms.domain.Building

cn.db.domain.tablename1

transaction-type="RESOURCE_LOCAL">

org.apache.openjpa.persistence.PersistenceProviderImpl

cn.db2.domain.tablename1

2.ApplicationContext.xml(写了两个。。还有个ApplicationContext1.xml内容差不多)

class="org.apache.commons.dbcp.BasicDataSource"

destroy-method="close">

value="com.ibm.db2.jcc.DB2Driver" />

value="jdbc:db2://127.0.0.1:50000/testdb" />

class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">

两个文件里面唯一不同的就是dataSource分别连接两个数据库,persistenceUnitName分别为DBNAME1和DBNAME2。

3.BeansFactory.java (还是两个,ClassPathResource分别写的ApplicationContext.xml和ApplicationContext1.xml)

public class BeansFactory {

private static Resource res = null;//new ClassPathResource("/cn/wiztek/remis/config/service.xml");//new ClassPathResource("/cn/wiztek/remis/config/service.xml");

private static BeanFactory factory = null;//new XmlBeanFactory(res);//new XmlBeanFactory(res);

static {

try {

System.out.println("!!!");

res = new ClassPathResource("ApplicationContext.xml");

factory = new XmlBeanFactory(res);

} catch (Throwable ex) {

System.err.println(ex);

ex.printStackTrace();

throw new ExceptionInInitializerError(ex);

}

}

public static Object getBean(String beanName){

return factory.getBean(beanName);

}

}

0

0

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2010-10-20 17:19

浏览 2199

评论

1 楼

weir2009

2011-03-01

contextConfigLocation

classpath:applicationContext.xml

这里怎么配置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值