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

推荐订阅源

罗磊的独立博客
SecWiki News
SecWiki News
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
量子位
M
MIT News - Artificial intelligence
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
TaoSecurity Blog
TaoSecurity Blog
博客园 - 【当耐特】
H
Heimdal Security Blog
腾讯CDC
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
S
Schneier on Security
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cybersecurity and Infrastructure Security Agency CISA
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
Application and Cybersecurity Blog
Application and Cybersecurity Blog
F
Full Disclosure
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threatpost
月光博客
月光博客
A
Arctic Wolf
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
T
Troy Hunt's Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
D
DataBreaches.Net
O
OpenAI News
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
小众软件
小众软件
V
Vulnerabilities – Threatpost
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
T
The Exploit Database - CXSecurity.com
Martin Fowler
Martin Fowler
美团技术团队
P
Privacy International News Feed

博客园 - 学海无涯

在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