SpringBoot Hikari数据源的正确配置是这样的
- [1. MySQL数据源配置](#1. MySQL数据源配置)
- [2. H2数据源配置](#2. H2数据源配置)
spring-boot version: spring-boot-starter:2.6.7
1. MySQL数据源配置
yaml
# 数据源配置
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/db_name
username: my_user
password: my_password
driver-class-name: com.mysql.cj.jdbc.Driver
hikari:
connection-test-query: SELECT 1
maximum-pool-size: 10
2. H2数据源配置
yaml
# 数据源配置
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:mem:db_name;DB_CLOSE_DELAY=-1;MODE=MYSQL
username: sa
password:
driver-class-name: org.h2.Driver
hikari:
connection-test-query: SELECT 1
maximum-pool-size: 10
h2:
console:
path: /h2
enabled: true
settings:
trace: true
web-allow-others: true
sql:
init:
platform: h2
schema-locations: classpath*:sql/init/schema/schema-{platform}.sql
data-locations: classpath*:sql/init/data/data-{platform}.sql