Get the App
SLTechnology News&Howtos  ›  Development  › 

How to configure connection pooling for spring boot2.0

Shulou Source: shulou.com Published: 2022-06-02 05:56:58 10月04日 Update

This article introduces the relevant knowledge of "how to configure connection pool in spring boot2.0". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

After springboot2.0, it comes with a hikari that claims to be the fastest connection pool in the world. Enter the following configuration directly in the configuration file:

# 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

But, I don't just want a connection pool, I also want a monitoring page, Ali's monitoring has so much content, I really think it's quite practical, directly on the page to see slow logs ah, session statistics ah, I still quite like it

In the past, druid wanted to configure the monitoring page. It needed to write a bunch of files and configurations. It was quite troublesome. After Ali made druid-starter for springboot, monitoring became easy. First, add it in the pom file:

com.alibaba druid-spring-boot-starter 1.1.14

Then add the configuration directly to the configuration file:

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. dataset.druid.stat-view-servlet.deny=192.168.1.73spring. dataset.druid.stat-view-servlet.reset-enable=false#The following 4 items must be changed in the future production environment!!! It has to change!! It has to change!! 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

Then restart the project can be, super simple, go to localhost:ip/druid can see the monitoring, the header in the dot diagram can be sorted Oh, analysis of slow query is because of what, very convenient

"Spring boot2.0 how to configure the connection pool" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Configuration monitoring files content pages practical more knowledge Ali the fastest learning and then not only the world dilemma reality situation articles logs cases Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft Docker MariaDB Linux