Spring data Jpa 配置c3p0连接池

Spring3.2.8+Hibernate4.2.12+SpringMVC+JPA框架:
http://blog.csdn.net/lx376693576/article/details/44116267

在上面的基础上加入c3p0连接池:

1、需要的jar包:
hibernate-c3p0-4.2.12.Final.jar //需与hibernate的版本对应
c3p0-0.9.1.2.jar

2、在persistece.xml文件中做如下配置:


<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
            http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

     
    <persistence-unit name="myJPA" transaction-type="RESOURCE_LOCAL">
      
    <provider>org.hibernate.ejb.HibernatePersistenceprovider>  
        <properties>
            
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
            
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
            
            <property name="hibernate.connection.username" value="root" />
            
            <property name="hibernate.connection.password" value="123456" />
            
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8" />
            
            <property name="hibernate.max_fetch_depth" value="3" />
            
            <property name="hibernate.hbm2ddl.auto" value="update" />    
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.format_sql" value="true" />
            <property name="javax.persistence.validation.mode" value="none"/>

            
            <property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider"/>
            
            <property name="hibernate.c3p0.min_size" value="1"/>
            
            <property name="hibernate.c3p0.max_size" value="20"/>
            
            <property name="hibernate.c3p0.timeout" value="5000"/>
              
             <property name="hibernate.c3p0.max_statements" value="100"/>
             
             <property name="hibernate.c3p0.idle_test_period" value="3000"/>
             
             <property name="hibernate.c3p0.acquire_increment" value="2"/>
             
             <property name="hibernate.c3p0.validate" value="true"/>
        properties>
    persistence-unit>
persistence>

3、然后就可以用了。

你可能感兴趣的:(Spring data Jpa 配置c3p0连接池)