經過下面的代碼,能夠查看當前正在使用的鏈接池:html
import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.sql.DataSource; @RunWith(SpringRunner.class) @SpringBootTest public class DataSourceTest { private static final Logger logger = LoggerFactory.getLogger(DataSourceTest.class); @Autowired private DataSource dataSource; @Test public void dataSourceInfo(){ logger.info(dataSource.toString()); } }
springboot2.1.0.RELEASE 的文檔: https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/
查看文檔能夠知道,若是咱們使用spring-boot-starter-jdbc或spring-boot-starter-data-jpa 「starter」,springboot將自動給咱們配置鏈接池HikariCP。java
使用hikari鏈接池,能夠查看對應的文檔:https://github.com/brettwooldridge/HikariCP/tree/HikariCP-3.2.0mysql
# DATASOURCE spring.datasource.url=jdbc:mysql://IP地址/數據庫名?serverTimezone=GMT%2B8 spring.datasource.username=xxxx spring.datasource.password=xxxx spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # DATASOURCE POOL #spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.maximum-pool-size=50 spring.datasource.hikari.auto-commit=true spring.datasource.hikari.idle-timeout=30000 spring.datasource.hikari.pool-name=DatebookHikariCP spring.datasource.hikari.max-lifetime=1800000 spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.connection-test-query=SELECT 1
其餘屬性本身查看文檔配置。git
參考文檔:
https://blog.csdn.net/woshilijiuyi/article/details/83010997github