栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Spring在Hibernate中配置内置的c3p0池

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Spring在Hibernate中配置内置的c3p0池

这是有关如何在数据源中配置c3p0的示例配置(来自我们的应用程序):

<bean id="dataSourceGlobal"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" >    <!--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会话中池。切勿同时使用两者,因为这会浪费资源。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/387886.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号