spring+hibernate的c0p3连接池配置

<?xml version= "1.0" encoding= "UTF-8"?> 
<!DOCTYPE beans  public  "-//SPRING//DTD BEAN//EN" 
    "http://www.springframework.org/dtd/spring-beans.dtd"
   <beans> 
           <!-- =========== Start of PERSISTENCE DEFINITIONS ============ -->
 
          <bean id= "placeholderConfig" class= "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
            <property name= "location"
                      <value>classpath:init.properties</value> 
                      
            </property> 
          </bean> 
          <bean id= "nativeJdbcExtractor" class= "org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor"/> 

           <bean id= "oracleLobHandle" class= "org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init= "true"
                        <property name= "nativeJdbcExtractor"
                                     <ref local= "nativeJdbcExtractor"/> 
                        </property> 
           </bean> 
              <bean id= "dataSource"  class= "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= "close"
                
                <property name= "driverClass"
                        <value>${datasource.driverClassName}</value> 
                </property> 
                <property name= "jdbcUrl"
                        <value>${datasource.url}</value> 
                </property> 
                                
                <property name= "properties"
                        <props> 
                                <prop key= "c3p0.minPoolSize">${hibernate.c3p0.minPoolSize}</prop> 
                                <prop key= "hc3p0.maxPoolSize">${hibernate.c3p0.maxPoolSize}</prop> 
                                <prop key= "hc3p0.timeout">${hibernate.c3p0.timeout}</prop> 
                                <prop key= "c3p0.max_statement">${hibernate.c3p0.max_statement}</prop> 
                                <prop key= "c3p0.testConnectionOnCheckout"> true</prop> 
                                <prop key= "user">${datasource.username}</prop> 
                <prop key= "password">${datasource.password}</prop> 
                                
                        </props> 
                </property> 
        </bean> 
        
        <!-- Hibernate SessionFactory --> 
        <bean id= "sessionFactory" class= "org.springframework.orm.hibernate3.LocalSessionFactoryBean"
                <property name= "dataSource"
                        <ref local= "dataSource"/> 
                </property> 
                <property name= "lobHandler"><ref local= "oracleLobHandle"/></property> 
                <property name= "mappingResources"
                        
                    <list>        
                            <value>com/cs2c/oa2/pojo/Testfile.hbm.xml</value>                                               
                    </list> 
                </property> 
                
                <property name= "hibernateProperties"
                      <props> 
                            <prop key= "hibernate.cglib.use_reflection_optimizer">${hibernate.cglib.use_reflection_optimizer}</prop> 
                            <prop key= "hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> 
                            <prop key= "hibernate.dialect">${hibernate.dialect}</prop> 
                            <prop key= "hibernate.default_schema">${hibernate.default_schema}</prop> 
                            <prop key= "hibernate.show_sql">${hibernate.show_sql}</prop> 
                       </props> 
                </property> 
        </bean> 
        
        
                
        <bean id= "test" class= "com.cs2c.oa2.test.TestHibernate"
        <property name= "sessionFactory">      
                        <ref bean= "sessionFactory"/> 
        </property>  
    </bean> 
    
   </beans> 

在配置的时候  cp30的属性的名字必须是  ''driverClass'  ,  'jdbcUrl',  'user'  ,  'password'  而  <property  name="properties">的名字也必须是“properties”,另外cp30配置文件的属性名也都是诸如:"c3p0.minPoolSize"、"hc3p0.maxPoolSize"等等, 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值