Spring双数据库配置_PHP教程

原创
2016-07-20 10:58:52 458浏览

有时候我们可能在一个项目中使用两个数据库,为了实现使用两个或多个数据库的功能,我们需要在Spring中配置相关信息。

首先是添加配置文件conf.properties

  1. "propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  2. "locations">
  3. classpath:config.properties

其次是添加数据源(${...}对应的是conf.properties中的配置信息)

  1. "dataSource_A" class="org.apache.commons.dbcp.BasicDataSource">
  2. "driverClassName" value="${A.driver_class}" />
  3. "url" value="${A.url}" />
  4. "username" value="${A.username}" />
  5. "password" value="${A.password}" />
  6. "dataSource_B" class="org.apache.commons.dbcp.BasicDataSource">
  7. "driverClassName" value="${B.driver_class}" />
  8. "url" value="${B.url}" />
  9. "username" value="${B.username}" />
  10. "password" value="${B.password}" />

之后是添加对应的sessionFactory:

  1. "sessionFactory_A" class="moretv.commons.spring.hibernate3.AnnotationSessionFactoryBean">
  2. "dataSource" ref="dataSource_A"/>
  3. "sessionFactory_B" class="moretv.commons.spring.hibernate3.AnnotationSessionFactoryBean">
  4. "dataSource" ref="dataSource_B"/>

在项目中的dao层有时会出现这样的配置信息:

  1. "XDao" class = "xxx.xxx.xDaoImpl">
  2. "sessionFactory" ref="sessionFactory">

为了实现使用两个不同的数据库,可以改成

  1. "font-family:'sans serif', tahoma, verdana, helvetica;font-size:13px;line-height:19px;white-space:normal;background-color:#ffffff;"> "font-family:'sans serif', tahoma, verdana, helvetica;white-space:normal;background-color:#ffffff;"> "XDao" class = "xxx.xxx.xDaoImpl">
  2. "sessionFactory" ref="sessionFactory_A">
  3. "XDao" class = "xxx.xxx.xDaoImpl">
  4. "sessionFactory" ref="sessionFactory_B">

这样就能实现双数据库了。。。。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445650.htmlTechArticle有时候我们可能在一个项目中使用两个数据库,为了实现使用两个或多个数据库的功能,我们需要在Spring中配置相关信息。 首先是添加配置...

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
上一条:PHP系列学习之日期函数_PHP教程 下一条:PHP 开源软件《个人管理系统》——技术规范_PHP教程

相关文章

查看更多