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
相关推荐
OtIo TALL15 小时前
redis7 for windows的安装教程
java
2601_9498177215 小时前
Spring Boot3.3.X整合Mybatis-Plus
spring boot·后端·mybatis
uNke DEPH16 小时前
Spring Boot的项目结构
java·spring boot·后端
xixingzhe216 小时前
idea启动vue项目
java·vue.js·intellij-idea
zhenxin012216 小时前
Spring Boot 3.x 系列【3】Spring Initializr快速创建Spring Boot项目
spring boot·后端·spring
wzl2026121316 小时前
企业微信定时群发技术实现与实操指南(原生接口+工具落地)
java·运维·前端·企业微信
凌波粒16 小时前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
曹牧16 小时前
Eclipse:悬停提示(Hover)
java·ide·eclipse
前端一小卒17 小时前
前端工程师的全栈焦虑,我用 60 天治好了
前端·javascript·后端
不停喝水17 小时前
【AI+Cursor】 告别切图仔,拥抱Vibe Coding: AI + Cursor 开启多模态全栈新纪元 (1)
前端·人工智能·后端·ai·ai编程·cursor