ssh框架下使用2种数据库来操作。一种是oracle,一种是sqlserver
下面是具体配置:
1、applicationContext-common.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="register*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="save*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="add*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="del*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="insert*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="update*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="modify*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="attach*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="exec*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="check*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="approve*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="process*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="init*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:a<mce:script type="text/javascript" src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js" mce_src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js"></mce:script><mce:script type="text/javascript" src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js" mce_src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js"></mce:script>dvice>
<aop:config>
<!-- 基本信息 -->
<aop:advisor advice-ref="txAdvice"
pointcut="execution(* cn.common.sys.service..*.*(..))" />
</aop:config>
<!-- sqlserver配置 -->
<bean id="sessionFactory_sqlserver"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:faxHibernate.cfg.xml</value>
</property>
</bean>
<bean id="transactionManager_sqlserver"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"
ref="sessionFactory_sqlserver">
</property>
</bean>
<tx:advice id="txAdvice_sqlserver"
transaction-manager="transactionManager_sqlserver">
<tx:attributes>
<tx:method name="register*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="save*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="add*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="del*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="insert*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="update*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="modify*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="attach*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="exec*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="check*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="approve*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="process*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="init*" propagation="REQUIRED"
rollback-for="exception" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<!-- 传真管理 -->
<aop:advisor advice-ref="txAdvice_sqlserver"
pointcut="execution(* cn.common.faxserver.service..*.*(..))" />
</aop:config>
</beans>
2、faxHibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hibernate.proxool.xml">faxProxool.xml</property>
<property name="hibernate.proxool.pool_alias">FaxDBPool</property>
<property name="hibernate.connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.jdbc.fetch_size">20</property>
<property name="hibernate.jdbc.use_streams_for_binary">
true
</property>
<property name="default_schema">dbo</property>
<!-- 传真收发 -->
<mapping
resource="cn/common/faxserver/po/TdbiFaxIn.hbm.xml" />
<mapping
resource="cn/common/faxserver/po/TdbiFaxOut.hbm.xml" />
</session-factory>
</hibernate-configuration>
faxProxool.xml
<?xml version='1.0' encoding='UTF-8'?>
<something-else-entirely>
<proxool>
<alias>FaxDBPool</alias>
<driver-url>jdbc:sqlserver://192.168.0.99:1433;databaseName=trafax</driver-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<driver-properties>
<property name="user" value="faxOp" />
<property name="password" value="faxOp" />
<property name="autoReconnect" value="true" />
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<house-keeping-test-sql>select getdate()</house-keeping-test-sql>
<prototype-count>5</prototype-count>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>5</minimum-connection-count>
</proxool>
</something-else-entirely>
3、hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.proxool.xml">Proxool.xml</property>
<property name="hibernate.proxool.pool_alias">MYPool</property>
<property name="hibernate.connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.jdbc.fetch_size">20</property>
<property name="hibernate.jdbc.use_streams_for_binary">
true
</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<mapping resource="cn/finefuture/cqwater/basetask/po/CallTOndutyperson.hbm.xml" />
</session-factory>
</hibernate-configuration>
Proxool.xml
<?xml version='1.0' encoding='UTF-8'?>
<something-else-entirely>
<proxool>
<alias>MYPool</alias>
<driver-url>
jdbc:oracle:thin:@192.168.0.99:1521:orcl
</driver-url>
<driver-class>
oracle.jdbc.driver.OracleDriver
</driver-class>
<driver-properties>
<property name="user" value="cqwater" />
<property name="password" value="cqwater" />
<property name="autoReconnect" value="true" />
</driver-properties>
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<prototype-count>5</prototype-count>
<maximum-connection-count>100</maximum-connection-count>
<minimum-connection-count>5</minimum-connection-count>
</proxool>
</something-else-entirely>
4、applicationContext-daos.xml在dao引入相应的sessionFactory就行了
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="customerDAO"
class="cn.common.platform.dao.impl.CustomerDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 发送传真dao -->
<bean id="tdbiFaxOutDAO"
class="cn.common.faxserver.dao.impl.TdbiFaxOutDAOImpl">
<property name="sessionFactory"
ref="sessionFactory_sqlserver">
</property>
</bean>
<!-- 接收传真dao -->
<bean id="tdbiFaxInDAO"
class="cn.common.faxserver.dao.impl.TdbiFaxInDAOImpl">
<property name="sessionFactory"
ref="sessionFactory_sqlserver">
</property>
</bean>
</beans>