这是有关如何在数据源中配置c3p0的示例配置(来自我们的应用程序):
<bean id="dataSourceGlobal" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${driver}" />
<property name="jdbcUrl" value="${server}" />
<property name="user" value="${user}" />
<property name="password" value="${passw}" />
<!-- these are C3P0 properties -->
<property name="acquireIncrement" value="${acquireIncrement}" />
<property name="minPoolSize" value="${minPoolSize}" />
<property name="maxPoolSize" value="${maxPoolSize}" />
<property name="maxIdleTime" value="${maxIdleTime}" />
</bean>
我们使用外部属性文件来配置一些参数,但是也可以在Spring中直接配置它们。
如果你希望hibernate处理池,则需要配置会话属性:
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionfactorybean">
<!--suppress InjectionValueTypeinspection -->
<property name="mappingResources" ref="hibernateMappingList" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<prop key="transaction.factory_class">
net.sf.hibernate.transaction.JDBCTransactionFactory
</prop>
<prop key="hibernate.transaction.factory_class">
net.sf.hibernate.transaction.JDBCTransactionFactory
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<prop name="hibernate.c3p0.min_size" value="2" />
<prop name="hibernate.c3p0.max_size" value="5" />
<prop name="hibernate.c3p0.timeout" value="600" />
<prop name="hibernate.c3p0.max_statements" value="0" />
<prop name="hibernate.c3p0.idle_test_period" value="300"/>
<prop name="hibernate.c3p0.acquire_increment" value="1" />
</props>
</property>
</bean>
你必须使用其中一种方法:在数据源中池或在hibernate会话中池。切勿同时使用两者,因为这会浪费资源。