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
相关推荐
GetcharZp11 分钟前
告别 Python 依赖!用 LangChainGo 打造高性能大模型应用,Go 程序员必看!
后端
阿里加多20 分钟前
第 4 章:Go 线程模型——GMP 深度解析
java·开发语言·后端·golang
likerhood37 分钟前
java中`==`和`.equals()`区别
java·开发语言·python
小小李程序员1 小时前
Langchain4j工具调用获取不到ThreadLocal
java·后端·ai
zs宝来了1 小时前
AQS详解
java·开发语言·jvm
GreenTea3 小时前
AI Agent 评测的下半场:从方法论到落地实践
前端·人工智能·后端
我是若尘4 小时前
Harness Engineering:2026 年 AI 编程的核心战场
前端·后端·程序员