本文主要是介绍spring+hibernate的c3p0 连接池配置,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
网上很多关于C3P0在spring+hibernate中的配置,几乎没有完全正确的,以下是根据c3p0的文档,又试验过多次,得出如下配置是正确的:
<!-- com.mchange.v2.c3p0.ComboPooledDataSource -->
<!-- start-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driverClass}" />
<property name="jdbcUrl" value="${jdbcUrl}" />
<property name="user" value="${user}" />
<property name="password" value="${password}" />
<property name="minPoolSize">
<value>4</value>
</property>
<property name="maxPoolSize">
<value>20</value>
</property>
<property name="maxIdleTime">
<value>1800</value>
</property>
<property name="acquireIncrement">
<value>2</value>
</property>
<property name="maxStatements">
<value>0</value>
</property>
<property name="initialPoolSize">
<value>2</value>
</property>
<property name="idleConnectionTestPeriod">
<value>1800</value>
</property>
<property name="acquireRetryAttempts">
<value>30</value>
</property>
<property name="breakAfterAcquireFailure">
<value>true</value>
</property>
<property name="testConnectionOnCheckout">
<value>false</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>ht/gisoa/entity/CmppSubmitCache.hbm.xml</value>
<value>ht/gisoa/entity/CmppDeliver.hbm.xml</value>
<value>ht/gisoa/entity/CmppSubmit.hbm.xml</value>
<value>ht/gisoa/entity/CmppReport.hbm.xml</value>
<value>ht/gisoa/entity/SGpstraceinfo.hbm.xml</value>
<value>ht/gisoa/entity/SDeviceinfo.hbm.xml</value>
<value>ht/gisoa/entity/SLbstraceinfo.hbm.xml</value>
<value>ht/gisoa/entity/Lbsschemainfo.hbm.xml</value>
</list>
</property>
</bean>
<!--end-->
这篇关于spring+hibernate的c3p0 连接池配置的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!