POM配置
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.8</version>
</dependency>
增加XML配置 spring-datasource.xml
<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd" default-autowire="byName">
<bean id="campDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close" >
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<!-- 基本屬性 url、user、password -->
<property name="url" value="${spring.datasource.url}" />
<property name="username" value="${spring.datasource.username}" />
<property name="password" value="${spring.datasource.password}" />
<!-- 配置初始化大小、最小、最大 -->
<property name="maxActive" value="19" />
<property name="initialSize" value="1" />
<property name="minIdle" value="3" />
<!-- 配置擷取連接配接等待逾時的時間 -->
<property name="maxWait" value="6000" />
<!-- 配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接配接,機關是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="6000" />
<!-- 配置一個連接配接在池中最小生存的時間,機關是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="30000" />
<property name="validationQuery" value="select 1" />
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="true" />
<property name="poolPreparedStatements" value="false" />
<property name="defaultAutoCommit" value="true" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="180" />
</bean>
</beans>
監控頁面位址:http://localhost:8080/druid/index.html
轉載于:https://my.oschina.net/ttscjr/blog/2990835