dennyLee2025

使用的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 中加入相应的依赖即可。

接下来我们来找找看这个类在哪里

 

 

 

分类:

技术点:

相关文章:

  • 2021-12-31
  • 2021-07-18
  • 2021-09-12
  • 2021-09-07
  • 2021-07-02
  • 2022-12-23
  • 2021-06-25
  • 2021-11-22
猜你喜欢
  • 2021-11-22
  • 2021-12-02
  • 2021-06-15
  • 2021-11-22
  • 2021-11-22
  • 2022-12-23
  • 2021-11-22
相关资源
相似解决方案