zoukankan      html  css  js  c++  java
  • 如何查看Spring Boot 默认的数据库连接池类型

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

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

     

  • 相关阅读:
    [ZJOI2006]书架
    luogu P3369 【模板】普通平衡树(splay)
    MegaCli是一款管理维护硬件RAID软件,可以通过它来了解当前raid卡的所有信息,包括 raid卡的型号,raid的阵列类型,raid 上各磁盘状态
    ipmi配置方法-20200328
    debian配置---->/etc/apt/sources.list apt基本源设置指南
    Alien 魔法:RPM 和 DEB 互转
    Debian 9 中设置网络
    SSH自动断开连接的原因-20200323
    mpstat命令
    dstat命令
  • 原文地址:https://www.cnblogs.com/dennyLee2025/p/13710571.html
Copyright © 2011-2022 走看看