问题描述
我正在使用spring / hibernate集成应用程序。我已经配置了c3p0连接池。我正在使用c3p0组合数据源。我应该在哪里指定组合数据源属性?
I am using spring/hibernate integrated application. I have configured c3p0 connection pooling. I am using c3p0 combopooled datasource. Where should I specify combopooled datasource properties?
在本节中?
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingLocations" value="classpath:hibernate-mapping.xml" />
<property name="hibernateProperties">
<props>
**//Here do I need to specify combopooled datasource properties?
//like acquireIncrement
acquireRetryAttempts
acquireRetryDelay
preferredTestQuery
maxPoolSize...etc**
</props>
</property>
<property name="dataSource" ref="dataSource" />
</bean>
还是在这里?
<bean id="rootDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
**//Here do i need to specify combopooled datasource properties?
//like acquireIncrement
acquireRetryAttempts
acquireRetryDelay
preferredTestQuery**
maxPoolSize...etc
</bean>
请建议我。
谢谢!
推荐答案
您可以在 c3p0.properties
文件中指定它们。只需将其放置在您的类路径的根中
You can specify them in a c3p0.properties
file. Just place it in the root of your classpath
,或者放置在名为 c3p0-config.xml
的xml文件中您的类路径的根
or, in xml file named c3p0-config.xml
also in the root of your classpath
,或者,如果您希望在Spring的Hibernate XML中使用它,则可以使用
or, if you want it in you spring xml for Hibernate you can use
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--<property name="lobHandler">
<ref local="lobHandler" />
</property>-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.driver_class">${jdbc.drivers}</prop>
<prop key="hibernate.connection.url">${jdbc.url}</prop>
<prop key="hibernate.connection.username">${jdbc.username}</prop>
<prop key="hibernate.connection.password">${jdbc.password}</prop>
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">100</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
我相信如果两者都存在,则Hibernate设置会覆盖使用c3po.properties文件。但是建议与c3po文档存在某些矛盾
I believe the Hibernate settings override the use of a c3po.properties file if both exist. however this post suggests some inconsistencies with the c3po docs
这篇关于应该在哪里指定c3p0属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!