SpringBoot数据源HikariCP与MyBatis整合

SpringBoot2默认数据库连接池为HikariCP

HikariCP GitHub地址

SpringBoot数据源HikariCP与MyBatis整合_第1张图片
image.png

pom文件:

    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.5.RELEASE
        
    

    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter
            
                
                    org.springframework.boot
                    spring-boot-starter-logging
                
            
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-configuration-processor
            true
        

        
            mysql
            mysql-connector-java
            5.1.41
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.0
        
    

配置文件

server:
  port: 8888
  tomcat:
    uri-encoding: UTF-8
  max-http-header-size: 80KB

spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/testDb?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true
    username: root
    password: 123456
    hikari:
      connection-timeout: 30000       # 等待连接池分配连接的最大时长(毫秒)
      minimum-idle: 5                 # 最小连接数
      maximum-pool-size: 20           # 最大连接数
      auto-commit: true               # 是否自动提交
      idle-timeout: 600000            # 连接超时的最大时长(毫秒)
      pool-name: DateSourceHikariCP   # 连接池名称
      max-lifetime: 1800000           # 连接的生命时长(毫秒)
      connection-test-query: SELECT 1 # 连接测试sql

mybatis:
  type-aliases-package: com.test.pojo
  mapper-locations: classpath:mapper/*.xml

你可能感兴趣的:(SpringBoot数据源HikariCP与MyBatis整合)