现在的位置: 首页 > 综合 > 正文

spring+hibernate的c3p0 连接池配置

2012年04月22日 ⁄ 综合 ⁄ 共 2042字 ⁄ 字号 评论关闭

网上很多关于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-->

 

抱歉!评论已关闭.