Spring Boot之默认连接池配置策略
注意:如果我们使用spring-boot-starter-jdbc 或 spring-boot-starter-data-jpa “starters”坐标,Spring Boot将自动配置HikariCP连接池,
因为HikariCP在性能和并发性相比其他连接池都要好。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
一、默认连接池策略
1.如果可以得到HikariCP连接池类,就优先配置HikariCP
2.否则,如果Tomcat pooling类可以得到,则使用它
3.如果上面两个都拿不到,则配置其他连接池,比如Commons DBCP2
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
yml文件:
spring:
datasource:
url: jdbc:mysql://localhost:3306/heimdallr?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
username: root
password: 123
driver-class-name: com.mysql.jdbc.Driver
# Spring Boot官方推荐的数据库连接池是Hikari,从一些第三方的评测结果看,Hikari的性能比Druid要好,但是Druid自带各种监控工具,背后又有阿里一直在为它背书
# hikari数据源配置,
hikari:
connection-test-query: SELECT 1 FROM DUAL
connection-timeout: 30000
maximum-pool-size: 20
max-lifetime: 1800000
minimum-idle: 5
二、自己指定连接池
通过设置spring.datasource.type属性,可以跳过默认连接池选择策略,比如指定druid连接池
spring:
datasource:
url: jdbc:mysql://localhost:3306/heimdallr?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
username: root
password: 123
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
max-idle: 10
max-wait: 1000
min-idle: 5
initial-size: 5
output.ansi.enabled: always
# 配置druid
druid:
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM t_user
testWhileIdle: true
testOnBorrow: true
testOnReturn: false
# 打开PSCache,并且指定每个连接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat,wall,log4j
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 合并多个DruidDataSource的监控数据
# useGlobalDataSourceStat: true
Spring Boot之默认连接池配置策略的更多相关文章
- 深入理解Spring Boot数据源与连接池原理
Create by yster@foxmail.com 2018-8-2 一:开始 在使用Spring Boot数据源之前,我们一般会导入相关依赖.其中数据源核心依赖就是spring‐boot‐s ...
- Spring Boot下Druid连接池+mybatis
目前Spring Boot中默认支持的连接池有dbcp,dbcp2, hikari三种连接池. 引言: 在Spring Boot下默认提供了若干种可用的连接池,Druid来自于阿里系的一个开源连 ...
- Spring Boot 添加Druid连接池(1.5 版本)
Druid是一个关系型数据库连接池,是阿里巴巴的一个开源项目,地址:https://github.com/alibaba/druid .Druid不但提供连接池的功能,还提供监控功能,可以实时查看数据 ...
- Spring Boot使用Druid连接池基本配置
以下为Spring Boot配置Druid 一.pom.xml配置 <dependency> <groupId>com.alibaba</groupId> < ...
- Spring中常用的连接池配置
首先,我们准备Jdbc属性文件 jdbc.properties,用于保存连接数据库的信息,利于我们在配置文件中的使用 jdbc.driver=com.mysql.jdbc.Driver jdbc.ur ...
- 结合 spring 使用阿里 Druid 连接池配置方法
1.数据源 <!-- 配置数据源 --> <bean name="dataSource" class="com.alibaba.druid.pool.D ...
- JBOSS默认连接池配置
jboss5.0mysql连接配置 <?xml version="1.0" encoding="UTF-8"?> <!-- The Hyper ...
- Spring Boot下Druid连接池的使用配置分析
https://blog.csdn.net/blueheart20/article/details/52384032
- spring+apache dbcp +oracle 连接池配置以及优化
特此记录 <!-- 数据源配置, 使用应用中的DBCP数据库连接池 --> <bean id="dataSource" class="org.apach ...
随机推荐
- Access导出excel
SELECT * INTO [excel .xls].Sheet1 FROM tableName
- 关于二进制——lowbit运算
lowbit(n)意思即为找出n在二进制表示下最后一位1即其后面的0所组成的数值,别的东西算法书上有,这里提出一个重要的公式 lowbit(n)=n&(~n+1)=n&(-n),这个有 ...
- Oracle SQL——inner jion;left join;right join的区别和使用场景
背景 在一次面试的时候,面试官让我说一下这三者的使用场景和区别,当时瞬间懵逼,哈哈.回来赶快看一看,记下来. 详解 inner join 等值查询:返回两张表中,联结字段值相等的组合记录 举例:所有学 ...
- Calculate difference between consecutive data points in a column from a file
cat > temp0015101269125 awk 'p{print $0-p}{p=$0}' temp00152-633-7 REF: https://www.unix.com/shel ...
- 未能加载文件或程序集“System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKe
https://bbs.csdn.net/topics/392046946 电脑没安装mvc4,应该是,解决这个问题一上午了今天,然后装完了后就好了! https://www.microsoft.co ...
- 关于C#引用ExceptionPolicy.HandleException(ex, "LogAndReplace", out exceptionToReplace);
http://www.cnblogs.com/Terrylee/archive/2006/07/03/enterprise_library2_1.html 要使用ExceptionPolicy.Han ...
- P3975 [TJOI2015]弦论
思路 一眼SAM板子,结果敲了一中午... 我还是太弱了 题目要求求第k小的子串 我们可以把t=0当成t=1的特殊情况,(所有不同位置的相同子串算作一个就是相当于把所有子串的出现位置个数(endpos ...
- NLP--- How to install the tool NLTK in Ubuntu ?
NLP--- How to install the tool NLTK in Ubuntu ? 1. open the website of NLTK and download it. https: ...
- Kylin知识点介绍
Kylin is an open source Distributed Analytics Engine from eBay Inc.that provides SQL interface and m ...
- 杭电hdu-6168 Numbers
这一题是考察排序与后续数据处理的题.我是用了map来给“和”做标记,把确定为a数组内数的数两两求和.给这些和标记,这样就可以很好的处理带有重复数的数据了~~ 贴个碼: #include<iost ...