spring_数据源c3p0

pom.xml 
<dependency> 
 <groupId>c3p0</groupId> 
 <artifactId>c3p0</artifactId> 
 <version>0.9.1</version> 
</dependency> 
--------------------------- 
config.properties
#c3p0数据源配置 
c3p0.jdbcUrl=jdbc:mysql://10.17.200.31:3306/super_acct?useUnicode=true&characterEncoding=utf8&mysqlEncoding=utf8 
c3p0.user=xxx 
c3p0.password=xxx 
c3p0.driverClass=com.mysql.jdbc.Driver 
c3p0.acquireIncrement=1 
c3p0.maxIdleTime=250 
c3p0.maxPoolSize=15 
c3p0.minPoolSize=5 
c3p0.initialPoolSize=5 
c3p0.acquireRetryDelay=1000 
c3p0.acquireRetryAttempts=60 
c3p0.breakAfterAcquireFailure=false 
// 
c3p0.testConnectionOnCheckin=true 
c3p0.automaticTestTable=T_CONNECT_POOL_TEST 
c3p0.idleConnectionTestPeriod=18000 
c3p0.checkoutTimeout=10000 
------------------------------------------------------- 
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:p="http://www.springframework.org/schema/p" 
  xmlns:context="http://www.springframework.org/schema/context" 
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-4.0.xsd"> 
  <!-- C3P0 configuration: --> 
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" scope="singleton"> 
    <property name="driverClass" value="${c3p0.driverClass}" />   
    <!--<property name="jdbcUrl" value="jdbc:mysql://10.17.5.103:3306/ZmData?useUnicode=true&amp;characterEncoding=utf8&amp;mysqlEncoding=utf8" /> -->   
    <property name="jdbcUrl" value="${c3p0.jdbcUrl}" /> 
    <property name="user" value="${c3p0.user}" />   
    <property name="password" value="${c3p0.password}" />   
    <property name="acquireIncrement" value="${c3p0.acquireIncrement}" />   
    <property name="initialPoolSize" value="${c3p0.initialPoolSize}" />   
    <property name="maxIdleTime" value="${c3p0.maxIdleTime}" />   
    <property name="maxPoolSize" value="${c3p0.maxPoolSize}" />   
    <property name="minPoolSize" value="${c3p0.minPoolSize}"/>   
    <property name="acquireRetryDelay" value="${c3p0.acquireRetryDelay}" />   
    <property name="acquireRetryAttempts" value="${c3p0.acquireRetryAttempts}" />   
    <property name="breakAfterAcquireFailure" value="${c3p0.breakAfterAcquireFailure}" />      

    <property name="testConnectionOnCheckin" value="${c3p0.testConnectionOnCheckin}" /> 
    <property name="automaticTestTable" value="${c3p0.automaticTestTable}" /> 
    <property name="idleConnectionTestPeriod" value="${c3p0.idleConnectionTestPeriod}" /> 
    <property name="checkoutTimeout" value="${c3p0.checkoutTimeout}" /> 
  </bean> 
</beans>   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring3中配置数据源,包括DBCP,C3P0,Proxool,Bonecp主要的数据源,里面包含这些数据源的jar文件和依赖文件及配置文件。。 如Bonecp目前听说是最快的数据源,速度是传统的c3p0的25倍, bonecp.properties文件: bonecp.driverClass=org.gjt.mm.mysql.Driver bonecp.jdbcUrl=jdbc:mysql://localhost/manytomany?useUnicode=true&characterEncoding=UTF-8 bonecp.username=root bonecp.password=2008 #分区数量 bonecp.partitionCount = 1 #每个分区含有的最小连接数 bonecp.minConnectionsPerPartition = 1 #每个分区含有的最大连接数 bonecp.maxConnectionsPerPartition = 2 #每次新增连接的数量 bonecp.acquireIncrement = 1 #连接池阀值,当 可用连接/最大连接 < 连接阀值 时,创建新的连接 bonecp.poolAvailabilityThreshold = 20 #连接超时时间阀值,获取连接时,超出阀值时间,则获取失败,毫秒为单位 bonecp.connectionTimeout = 10000 #连接池助手线程数量,可设置为0,该参数会降低运行速度,但程序有大量连接时,有助于提升高并发程序的性能 bonecp.releaseHelperThreads = 0 #语句助手线程数,可设置为0,该参数会降低运行速度,但程序有大量的查询语句时,有助于提升高并发程序的性能 bonecp.statementReleaseHelperThreads = 0 #测试连接有效性的间隔时间,单位分钟 bonecp.idleConnectionTestPeriod = 60 #连接的空闲存活时间,当连接空闲时间大于该阀值时,清除该连接 bonecp.idleMaxAge = 240 #语句缓存个数,默认是0 bonecp.statementsCacheSize = 5 Spring中的配置信息 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <context:annotation-config /> <context:component-scan base-package="com.mvc" /> <mvc:annotation-driven /> <mvc:resources mapping="/resources/**" location="/resources/" /> <mvc:default-servlet-handler /> <aop:config proxy-target-class="true"/> <tx:annotation-driven transaction-manager="txManager"/> <!-- 采用单数据源事务控制方式,通过注解来定义事务--> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <value>classpath:proxool.properties</value> </property> </bean> <bean id="dataSource" class="org.logicalcobwebs.proxool.ProxoolDataSource" destroy-method="close"> <property name="driver"> <value>org.gjt.mm.mysql.Driver</value> </property> <property name="driverUrl"> <value>jdbc:mysql://localhost/manytomany?useUnicode=true&characterEncoding=UTF-8</value> </property> <property name="user"> <value>root</value> </property> <property name="password"> <value>2008</value> </property> <property name="alias"> <value>Db_name</value> </property> <property name="houseKeepingSleepTime"> <value>90000</value> </property> <property name="prototypeCount"> <value>50</value> </property> <property name="maximumConnectionCount"> <value>50</value> </property> <property name="minimumConnectionCount"> <value>2</value> </property> <property name="trace"> <value>true</value> </property> <property name="verbose"> <value>true</value> </property> </bean> </beans>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值