Spring Boot学习之整合HikariCP数据库连接池

HikariCP介绍

HiKariCP是数据库连接池的一个后起之秀,号称性能最好,可以完美地PK掉其他连接池。是一个高性能的JDBC连接池,基于BoneCP做了不少的改进和优化。超快,快到连Spring Boot2都宣布支持了。
官网:https://github.com/brettwooldridge/HikariCP
视频教程地址点这里

pom.xml配置

<!-- ${hikaricp.version}调用springboot自带的版本 -->
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>${hikaricp.version}</version>
        </dependency>
        <!-- 排除tomcat-jdbc,才能使用HikariCP -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.tomcat</groupId>
                    <artifactId>tomcat-jdbc</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--mysql驱动-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
        </dependency>

配置数据源

  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.141.130:3306/myshop?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: 123456
    hikari:
      minimum-idle: 5
      idle-timeout: 600000
      maximum-pool-size: 10
      auto-commit: true
      pool-name: MyHikaricP
      max-lifetime: 1800000
      connection-timeout: 30000
      connection-test-query: SELECT 1

你可能感兴趣的:(springboot)