Druid是Java语言中最好的数据库连接池。Druid能够提供强大的监控和扩展功能。
- 正式版本下载:
maven中央仓库: http://central.maven.org/maven2/com/alibaba/druid/
Alibaba开源下载: http://code.alibabatech.com/mvn/releases/com/alibaba/druid/ - 快照版本下载
http://code.alibabatech.com/mvn/snapshots/com/alibaba/druid/
web.xml配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<filter>
<filter-name>DruidWebStatFilter</filter-name>
<filter-
class
>com.alibaba.druid.support.http.WebStatFilter</filter-
class
>
<init-param>
<param-name>exclusions</param-name>
<param-value>/
static
/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>DruidWebStatFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- druid监控 -->
<servlet>
<servlet-name>DruidStatView</servlet-name>
<servlet-
class
>com.alibaba.druid.support.http.StatViewServlet</servlet-
class
>
</servlet>
<servlet-mapping>
<servlet-name>DruidStatView</servlet-name>
<url-pattern>/druid/*</url-pattern>
</servlet-mapping>
|
spring.xml配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<!-- 数据源配置, 使用 BoneCP 数据库连接池 -->
<bean id=
"dataSource"
class
=
"com.alibaba.druid.pool.DruidDataSource"
init-method=
"init"
destroy-method=
"close"
>
<!-- 数据源驱动类可不写,Druid默认会自动根据URL识别DriverClass -->
<property name=
"driverClassName"
value=
"com.mysql.jdbc.Driver"
/>
<!-- 基本属性 url、user、password -->
<property name=
"url"
value=
"jdbc:mysql://127.0.0.1:3306/html580?useUnicode=true&characterEncoding=utf-8"
/>
<property name=
"username"
value=
"root"
/>
<property name=
"password"
value=
"123456"
/>
<!-- 配置初始化大小、最小、最大 -->
<property name=
"initialSize"
value=
"3"
/>
<property name=
"minIdle"
value=
"3"
/>
<property name=
"maxActive"
value=
"20"
/>
<!-- 配置获取连接等待超时的时间 -->
<property name=
"maxWait"
value=
"60000"
/>
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name=
"timeBetweenEvictionRunsMillis"
value=
"60000"
/>
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name=
"minEvictableIdleTimeMillis"
value=
"300000"
/>
<property name=
"validationQuery"
value=
"SELECT 'x'"
/>
<property name=
"testWhileIdle"
value=
"true"
/>
<property name=
"testOnBorrow"
value=
"false"
/>
<property name=
"testOnReturn"
value=
"false"
/>
<!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用)
<property name=
"poolPreparedStatements"
value=
"true"
/>
<property name=
"maxPoolPreparedStatementPerConnectionSize"
value=
"20"
/> -->
<!-- 配置监控统计拦截的filters -->
<property name=
"filters"
value=
"stat"
/>
</bean>
|
数据源集成了监控页面 输入工程后加druid/index.html。
提供了比较详细的监控,不错的实现哟。