码迷,mamicode.com
首页 > 其他好文 > 详细

druid(德鲁伊)数据源的使用和配置 阿里出品

时间:2016-01-24 22:29:53      阅读:1508      评论:0      收藏:0      [点我收藏+]

标签:

pom.xml

<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.0.9</version>
</dependency>

现看配置吧:

jdbc.properties

druid.url=jdbc:mysql://localhost:3306/ulewo?useUnicode=true&characterEncoding=utf8&autoReconnect=true
druid.driverClassName=com.mysql.jdbc.Driver  
druid.username=root
druid.password=root
       
druid.filters=stat
   
druid.maxActive=20
druid.initialSize=1
druid.maxWait=60000
druid.minIdle=10
maxIdle:100  
   
druid.timeBetweenEvictionRunsMillis=60000
druid.minEvictableIdleTimeMillis=300000
   
druid.validationQuery=SELECT ‘x‘
druid.testWhileIdle=true
druid.testOnBorrow=false
druid.testOnReturn=false
#poolPreparedStatements:true  
druid.maxOpenPreparedStatements=20
  
#对于建立连接过长的连接强制关闭  
druid.removeAbandoned:true
#如果连接建立时间超过了30分钟,则强制将其关闭  
druid.removeAbandonedTimeout:1800
#将当前关闭动作记录到日志  
druid.logAbandoned:true

spring配置:

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"  
        destroy-method="close">  
        <property name="url" value="${druid.url}" />  
        <property name="username" value="${druid.username}" />  
        <property name="password" value="${druid.password}" />  
        <property name="driverClassName" value="${druid.driverClassName}" />  
        <property name="filters" value="${druid.filters}" />  
  
        <property name="maxActive" value="${druid.maxActive}" />  
        <property name="initialSize" value="${druid.initialSize}" />  
        <property name="maxWait" value="${druid.maxWait}" />  
        <property name="minIdle" value="${druid.minIdle}" />  
  
        <property name="timeBetweenEvictionRunsMillis" value="${druid.timeBetweenEvictionRunsMillis}" />  
        <property name="minEvictableIdleTimeMillis" value="${druid.minEvictableIdleTimeMillis}" />  
  
        <property name="validationQuery" value="${druid.validationQuery}" />  
        <property name="testWhileIdle" value="${druid.testWhileIdle}" />  
        <property name="testOnBorrow" value="${druid.testOnBorrow}" />  
        <property name="testOnReturn" value="${druid.testOnReturn}" />  
        <property name="maxOpenPreparedStatements"  
            value="${druid.maxOpenPreparedStatements}" />  
        <property name="removeAbandoned" value="${druid.removeAbandoned}" /> <!-- 打开removeAbandoned功能 -->  
        <property name="removeAbandonedTimeout" value="${druid.removeAbandonedTimeout}" /> <!-- 1800秒,也就是30分钟 -->  
        <property name="logAbandoned" value="${druid.logAbandoned}" /> <!-- 关闭abanded连接时输出错误日志 -->  
    </bean>

druid(德鲁伊)数据源的使用和配置 阿里出品

标签:

原文地址:http://www.cnblogs.com/mfc-itblog/p/5156094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!