SpringBoot Hikari数据源的正确配置是这样的

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
相关推荐
Jagger_1 天前
AI 洪水淹到脖子了:剩下的是什么?我们该往哪儿跑?
后端
Victor3561 天前
MongoDB(28)什么是地理空间索引?
后端
Victor3561 天前
MongoDB(29)如何创建索引?
后端
皮皮林5511 天前
面试官:什么是 fail-fast?什么是 fail-safe?
后端
陈随易1 天前
前端大咖mizchi不满Rust、TypeScript却爱上MoonBit
前端·后端·程序员
雨中飘荡的记忆1 天前
Multi-Agent + Skills + Spring AI 构建自主决策智能体
后端·spring
我叫黑大帅1 天前
Go 语言并发编程的 “工具箱”
后端·面试·go
兆子龙1 天前
ahooks useRequest 深度解析:一个 Hook 搞定所有请求
java·javascript