文档章节

SSH+连接池配置多数据库

endlessBei
 endlessBei
发布于 2014/09/04 10:23
字数 865
阅读 10
收藏 0

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>
 

 

 

© 著作权归作者所有

endlessBei
粉丝 1
博文 35
码字总数 10205
作品 0
渝中
程序员
私信 提问
求javaweb方向的前辈们,关于三大框架中配置文件的一些疑问~很急

我在进行ssh整合的时候有时候数据库的连接池信息和实体类的映射怎么都可以配置在spring的配置文件里面?有时候甚至都不需要hibernate.cfg.xml这个配置文件,难道spring已经完全把hibernate融...

上帝爱众生
2015/03/19
391
0
hibernate、c3p0、jdbc理解

大家好,请教大家概念问题,hibernate、c3p0、jdbc这三者是什么关系, 我的理解是:hibernate 是对jdbc的封装,可以面向对象(实体类)实现数据操作,jdbc就是java api提供的连接操作数据库的...

樱木花道VS康
2017/06/30
270
2
数据库连接池

这两天公司的事情不忙,看了一下ssh的框架,在看spring框架的时候看到数据源这一块。就想知道数据源这一块是怎么实现的,以前也有学习过数据源,但感觉没那么系统。在网上看到一个详细介绍数...

zdatbit
2016/05/12
100
0
java一体化构架--Jspx.net

一套开源的 Jspx.net Framework (简实构架)是一套开源的java一体化构架,丢掉了jsp编译的烦恼和使用tag的麻烦, 完整的架构体系,包括了ui、ioc、cache、连接池、验证、模板引擎、数据库中间件等...

jspxnet
2014/06/01
1K
0
Spring Boot 2.0.X 多数据源及连接池配置

一、单数据源 我们在使用Spring Boot配置单数据源的时候很简单,只要在配置文件中加上基本的数据库连接信息和连接池配置信息就可以,通常情况下不需要指定driver-class-name,Spring Boot可以...

皮皮猫32
01/14
1K
0

没有更多内容

加载失败,请刷新页面

加载更多

zk中ToBeAppliedRequestProcessor解析

ToBeAppliedRequestProcessor在Leader中 在已处理事务和最后处理事务处理器之间,处理器链上下一个是FinalRequestProcessor public void processRequest(Request request) throws RequestPro...

writeademo
11分钟前
1
0
Allegro快捷键设置-PCB环境

立题简介: 内容:简单介绍Allegro绘制的PCB环境下的快捷键; 来源:实际使用得出; 作用:对Allegro绘制PCB快捷键进行介绍; PCB环境:Cadence 16.6; 立题详解: 对“allegro”板而言,其在...

demyar
12分钟前
1
0
idea maven web项目启动build时报错java.lang.NullPointerException

之前还好好的,重启一下idea就报这个错了,大概率是tomcat没杀掉端口被占用了,在tomcat配置中更换一下sever端口就好了

宇辰OSC
15分钟前
1
0
weed3-2.3.1.查询之输出

Weed3 一个超轻量级ORM框架(只有0.1Mb哦) 源码:https://github.com/noear/weed3 源码:https://gitee.com/noear/weed3 查询可是个复杂的话题了,可能我们80%的数据库处理都在查询。 今天先...

刘之西东
16分钟前
1
0
【Android JetPack系列】数据绑定:DataBinding

参考MVVM

Agnes2017
24分钟前
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部