惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cisco Blogs
AWS News Blog
AWS News Blog
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
美团技术团队
T
Threatpost
S
Schneier on Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Cyber Attacks, Cyber Crime and Cyber Security
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes
Blog — PlanetScale
Blog — PlanetScale
C
Cybersecurity and Infrastructure Security Agency CISA
F
Full Disclosure
博客园_首页
N
Netflix TechBlog - Medium
Security Latest
Security Latest
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Register - Security
The Register - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recent Announcements
Recent Announcements
博客园 - Franky
P
Palo Alto Networks Blog
Project Zero
Project Zero
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Cisco Talos Blog
Cisco Talos Blog
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 【当耐特】
GbyAI
GbyAI

博客园 - 学海无涯

在CentOS上安装和部署Shiny Server Hibernate实体生成JSON的问题及解决 在CentOS上安装并运行SparkR CentOS 6主机上的RStudio Server安装步骤 Oracle用户密码过期后重置SYS用户密码 在CentOS中将/var等已有目录挂载到新添加的硬盘 CentOS中的常用命令 Java在Web项目中读取properties文件 安装和配置CentOS时钟同步服务 在CentOS中安装中文支持 在CentOS 6.x中支持exfat格式的U盘(移动硬盘) CentOS常见问题 CentOS MySQL 配置 显示远程网站上的图片 【转载】我们什么时候结婚 纪念新生命诞生 真爱的四个阶段 【转贴词解】富士山下 与寂寞有染,与爱情无关
Druid连接池初探
学海无涯 · 2014-09-15 · via 博客园 - 学海无涯

Druid首先是一个数据库连接池,但它不仅仅是一个数据库连接池,它还包含一个ProxyDriver,一系列内置的JDBC组件库,一个SQL Parser。

  • Maven配置

在pom.xml文件中添加如下配置节——

1 <dependency>
2   <groupId>com.alibaba</groupId>
3   <artifactId>druid</artifactId>
4   <version>${druid-version}</version>
5 </dependency>
  • Spring数据源配置

在Spring配置文件中添加如下配置节——

 1 <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">   
 2     <property name="url" value="${jdbc_url}" />  
 3     <property name="username" value="${jdbc_user}" />  
 4     <property name="password" value="${jdbc_password}" />  
 5        
 6     <property name="filters" value="stat" />  
 7    
 8     <property name="maxActive" value="20" />  
 9     <property name="initialSize" value="1" />  
10     <property name="maxWait" value="60000" />  
11     <property name="minIdle" value="1" />  
12    
13     <property name="timeBetweenEvictionRunsMillis" value="60000" />  
14     <property name="minEvictableIdleTimeMillis" value="300000" />  
15    
16     <property name="validationQuery" value="SELECT 'x'" />  
17     <property name="testWhileIdle" value="true" />  
18     <property name="testOnBorrow" value="false" />  
19     <property name="testOnReturn" value="false" />  
20        
21     <property name="poolPreparedStatements" value="true" />  
22     <property name="maxPoolPreparedStatementPerConnectionSize" value="50" />  
23 </bean>
  • Web监控页面配置

在web.xml中添加如下配置节,即可通过http://{ip}:{port}/druid进行监控。

1 <servlet>
2     <servlet-name>DruidStatView</servlet-name>
3     <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
4 </servlet>
5 <servlet-mapping>
6     <servlet-name>DruidStatView</servlet-name>
7     <url-pattern>/druid/*</url-pattern>
8 <servlet-mapping>

View Code