标签:
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}"