本篇内容介绍了“spring boot2.0怎么配置连接池”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
springboot2.0之后,自带了一个号称全世界最快的连接池hikari,直接在配置文件里输入以下配置即可:
# Hikari will use the above plus the following to setup connection poolingspring.datasource.type=com.zaxxer.hikari.HikariDataSourcespring.datasource.hikari.minimum-idle=5spring.datasource.hikari.maximum-pool-size=15spring.datasource.hikari.auto-commit=truespring.datasource.hikari.idle-timeout=30000spring.datasource.hikari.pool-name=HikariCPspring.datasource.hikari.max-lifetime=1800000spring.datasource.hikari.connection-timeout=30000spring.datasource.hikari.connection-test-query=SELECT 1
但是呢,我不仅仅想要连接池,我还想要一个监控页面,阿里的监控有这么多内容,我真的觉得挺实用的,直接在页面上看慢日志啊,session统计啊,我还是挺喜欢的
过去的druid想要配置监控页面,需要写一堆文件和配置,还挺麻烦的,阿里针对springboot做了druid-starter之后,监控就变得轻松容易了,首先在pom文件加入:
<!-- https://mvnrepository.com/artifact/com.alibaba/druid-spring-boot-starter --><dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.14</version></dependency>
然后在配置文件里直接加入配置:
spring.datasource.druid.initial-size=5spring.datasource.druid.min-idle=5spring.datasource.druid.maxActive=20spring.datasource.druid.maxWait=60000spring.datasource.druid.timeBetweenEvictionRunsMillis=60000spring.datasource.druid.minEvictableIdleTimeMillis=300000spring.datasource.druid.validationQuery=SELECT 1 spring.datasource.druid.testWhileIdle=truespring.datasource.druid.testOnBorrow=falsespring.datasource.druid.testOnReturn=falsespring.datasource.druid.poolPreparedStatements=truespring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20spring.datasource.druid.filters=stat,wallspring.datasource.druid.connectionProperties=druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000spring.datasource.druid.web-stat-filter.enabled=truespring.datasource.druid.web-stat-filter.url-pattern=/*spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*spring.datasource.druid.stat-view-servlet.deny=192.168.1.73spring.datasource.druid.stat-view-servlet.reset-enable=false#以下4项,将来上生产环境以后一定要改!!!!!一定要改!!!!!一定要改!!!!!spring.datasource.druid.stat-view-servlet.url-pattern=/druid/*spring.datasource.druid.stat-view-servlet.allow=127.0.0.1,*spring.datasource.druid.stat-view-servlet.login-username=adminspring.datasource.druid.stat-view-servlet.login-password=123456
然后重新启动项目就可以了,超级简单,去 localhost:ip/druid就可以看监控了,点图中的表头可以排序哦,分析慢查询是因为什么,很方便
“spring boot2.0怎么配置连接池”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!