• 如何查看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 中加入相应的依赖即可。

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

     

  • 相关阅读:
    懒加载
    通过Xib自定义控件
    自定义控件
    swiper_banner图的封装
    uni-app中封装的search和scroll-view
    使用git从创建仓库或项目到push到远程并创建分支常用命令
    随手封装一个简单的日期组件(基于ele-ui的基础上)
    封装的一个时间条插件
    websocket的封装2
    websocket的封装1(做vue中的通信经常也是大概率用到的)
  • 原文地址:https://www.cnblogs.com/dennyLee2025/p/13710571.html
Copyright © 2020-2023  润新知