问题
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?
In this section?
<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>
Or here?
<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>
Please suggest me.
Thanks!
回答1:
You can specify them in a c3p0.properties
file. Just place it in the root of your classpath
or, in xml file named c3p0-config.xml
also in the root of your classpath
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>
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
回答2:
Those should go on to the data source bean (rootDataSource). Once you pass a data source to the LocalSessionFactoryBean hibernate will not be creating the connection pool - so the properties specified under hibernateProperties will be ignored.
All the properties you want to set are available as setter methods on ComboPooledDataSource. Add more property tags to your data source bean and specify the value for those there.
<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}" />
<property name="password" value="${jdbc.password}" />
<property name="acquireRetryAttempts" value="..." />
<property name="acquireRetryDelay" value="..." />
<property name="preferredTestQuery" value="..." />
<property name="maxPoolSize" value="..." />
</bean>
来源:https://stackoverflow.com/questions/10553797/where-should-c3p0-properties-specified