偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Spring雙數(shù)據(jù)庫配置

開發(fā) 前端 后端
有時候我們可能在一個項(xiàng)目中使用兩個數(shù)據(jù)庫,為了實(shí)現(xiàn)使用兩個或多個數(shù)據(jù)庫的功能,我們需要在Spring中配置相關(guān)信息……

有時候我們可能在一個項(xiàng)目中使用兩個數(shù)據(jù)庫,為了實(shí)現(xiàn)使用兩個或多個數(shù)據(jù)庫的功能,我們需要在Spring中配置相關(guān)信息。

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

  1. <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  2.         <property name="locations">  
  3.             <list>  
  4.                 <value>classpath:config.properties</value>  
  5.             </list>  
  6.         </property>  
  7. </bean> 

其次是添加數(shù)據(jù)源(${...}對應(yīng)的是conf.properties中的配置信息)

  1. <!--對應(yīng)數(shù)據(jù)A的數(shù)據(jù)源-->  
  2. <bean id="dataSource_A" class="org.apache.commons.dbcp.BasicDataSource">  
  3.         <property name="driverClassName" value="${A.driver_class}" />  
  4.         <property name="url" value="${A.url}" />  
  5.         <property name="username" value="${A.username}" />  
  6.         <property name="password" value="${A.password}" />  
  7. </bean>  
  8. <!--對應(yīng)數(shù)據(jù)庫B的數(shù)據(jù)源-->  
  9. <bean id="dataSource_B" class="org.apache.commons.dbcp.BasicDataSource">  
  10.         <property name="driverClassName" value="${B.driver_class}" />  
  11.         <property name="url" value="${B.url}" />  
  12.         <property name="username" value="${B.username}" />  
  13.         <property name="password" value="${B.password}" />  
  14. </bean> 

之后是添加對應(yīng)的sessionFactory:

  1. <!-- A的sessionFactory -->  
  2.     <bean id="sessionFactory_A" class="moretv.commons.spring.hibernate3.AnnotationSessionFactoryBean">  
  3.         <property name="dataSource" ref="dataSource_A"/>  
  4.     </bean>  
  5. <!-- B的sessionFactory -->  
  6.     <bean id="sessionFactory_B" class="moretv.commons.spring.hibernate3.AnnotationSessionFactoryBean">  
  7.         <property name="dataSource" ref="dataSource_B"/>      
  8.     </bean> 

在項(xiàng)目中的dao層有時會出現(xiàn)這樣的配置信息:

  1. <bean id = "XDao" class = "xxx.xxx.xDaoImpl">  
  2. <property name="sessionFactory" ref="sessionFactory"></property>  
  3. </bean> 

為了實(shí)現(xiàn)使用兩個不同的數(shù)據(jù)庫,可以改成

  1. <span style="font-family:'sans serif', tahoma, verdana, helvetica;font-size:13px;line-height:19px;white-space:normal;background-color:#ffffff;">&nbsp;</span><span style="font-family:'sans serif', tahoma, verdana, helvetica;white-space:normal;background-color:#ffffff;"><!--使用A數(shù)據(jù)庫的DAO--></span> <bean id = "XDao" class = "xxx.xxx.xDaoImpl">  
  2. <property name="sessionFactory" ref="sessionFactory_A"></property>  
  3. </bean>  
  4. <!--使用B數(shù)據(jù)庫的DAO-->  
  5. <bean id = "XDao" class = "xxx.xxx.xDaoImpl">  
  6. <property name="sessionFactory" ref="sessionFactory_B"></property>  
  7. </bean> 

這樣就能實(shí)現(xiàn)雙數(shù)據(jù)庫了。。。。

原文鏈接:http://my.oschina.net/u/241670/blog/80148

責(zé)任編輯:林師授 來源: OSCHINA
相關(guān)推薦

2021-10-28 19:28:04

數(shù)據(jù)庫開發(fā)Spring

2010-04-19 16:01:54

2011-03-03 11:07:57

Spring數(shù)據(jù)庫訪問ORM

2011-06-23 18:37:02

Qt 數(shù)據(jù)庫

2011-02-28 15:45:12

2011-04-14 11:09:14

MySQL數(shù)據(jù)庫

2015-10-22 16:26:59

MySQL數(shù)據(jù)庫雙主配置

2011-08-15 23:14:34

Oraclerman環(huán)境配置

2011-03-08 10:58:09

Sybase數(shù)據(jù)庫

2018-01-08 18:47:39

Windows 10數(shù)據(jù)庫管家婆軟件

2017-10-25 15:27:52

MySQL數(shù)據(jù)庫超時設(shè)置

2011-01-21 11:12:01

Spring

2011-03-07 09:26:37

2011-03-24 14:59:42

2019-10-12 16:15:13

MySQL數(shù)據(jù)庫多實(shí)例

2011-08-10 15:46:29

數(shù)據(jù)庫

2010-05-26 18:16:31

MySQL數(shù)據(jù)庫安裝

2019-11-06 09:23:20

數(shù)據(jù)庫配置網(wǎng)絡(luò)

2010-04-02 16:03:20

Oracle數(shù)據(jù)庫

2009-06-16 09:25:31

JBoss配置
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號