I've a project of Spring and Hibernate, but that use a lot of conections to my database (MYSQL). I know that I should implement a C3P0 to manage Pool conection but i dont know how?. Plase take me a help.
Hibernate's config:
<bean id="dataSource" class="org.springframework.jdbc.dat开发者_开发知识库asource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/oasis"/>
<property name="username" value="root"/>
<property name="password" value="mysql"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan">
<list>
<value>com.app.oasis.model.base</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<tx:annotation-driven/>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
Where do I have to add the C3P0 config?
Add the C3P0 jar file (download from c3p0 website or use maven) to your classpath and create your dataSource using com.mchange.v2.c3p0.ComboPooledDataSource
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost/oasis"/>
<property name="user" value="root"/>
<property name="password" value="mysql"/>
<!-- Various configuration properties can be set here -->
</bean>
精彩评论