转自:http://conect.iteye.com/blog/198826
Spring 配置proxool连接池
在我的工程中,文件名叫hibernate.cfg.xml,和entity放在一起
<?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:context="http://www.springframework.org/schema/context"
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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource" destroy-method="close">
<property name="driver" value="${hibernate.driverClass}" />
或者直接写成<property name="driver"> <value>com.mysql.jdbc.Driver</value></property>
<property name="driverUrl" value="${hibernate.jbdc.url}" />
<property name="user" value="${hibernate.jbdc.user}" />
<property name="password" value="${hibernate.jdbc.password}" />
<!-- <alias>是连接池的别名,proxoolPool连接池的一种,此外经常使用的连接池还有C3P0 -->
<property name="alias" value="proxoolPool" />
<!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回
收,超时的销毁 (默认30秒)-->
<property name="houseKeepingSleepTime" value="30000" />
<!-- 最少保持的空闲连接数 (默认5个)-->
<property name="prototypeCount" value="20" />
<!-- 设置连接池内生成的最大连接数/在连接池中所有数据库连接的最大数目(默认15个) -->
<property name="maximumConnectionCount" value="${hibernate.jdbc.maxConn}" />
<!-- 设置连接池内生成的最小连接数/在连接池中可用的数据库连接的最少数目(默认5个)-->
<property name="minimumConnectionCount" value="${hibernate.jdbc.minConn}" />
<!-- 在Consonl中显示sql -->
<property name="trace" value="true" />
<property name="verbose" value="true" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="schemaUpdate" value="${hibernate.schemaUpdate}" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.use_outer_join">true</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.use_streams_for_binary">true</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
<prop key="hibernate.query.substitutions">true 1,false 0,yes 'Y',no 'N'</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>com.mysteel.entity.xxx</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
Spring配C3P0连接池