使用的Spring Boot的版本:2.3.4.RELEASE
先给出答案:com.zaxxer.hikari.HikariDataSource
怎么知道的呢?
新建一个Spring boot项目:springbootTest
配置pom.xml
<dependencies> <!-- SpringBoot 核心包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- Mysql驱动包 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.21</version> </dependency> <!-- spring-boot-starter-jdbc --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> </dependencies>
配置application.yml
spring: #配置MySQL连接 datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/mysql-test?characterEncoding=UTF-8 username: root password: 123456
#type: com.alibaba.druid.pool.DruidDataSource
写一个类来输出Spring Boot 默认的数据库连接池类型
import javax.sql.DataSource; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; @Component public class ApplicationTest implements ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { DataSource dataSource = applicationContext.getBean(DataSource.class) ; System.out.println("----------------------------------"); System.out.println(dataSource.getClass().getName()); System.out.println("----------------------------------"); } }
启动Spring Boot 即可看到启动日志中打印了:
可以看到Spring Boot 默认的数据库连接池类型:Hikari
可以在application.yml 的配置中修改连接池类型,具体看前面的配置,在pom.xml 中加入相应的依赖即可。
接下来我们来找找看这个类在哪里