1. Spring Boot下H2数据库的常用配置项

# 指定数据库的类型
spring.datasource.platform=h2 # 数据库连接地址(文件模式)
## AUTO_SERVER=TRUE,启动自动混合模式,允许开启多个连接,该参数不支持在内存中运行模式
## DB_CLOSE_ON_EXIT=FALSE,当虚拟机退出时并不关闭数据库
spring.datasource.url=jdbc:h2:file:./h2/code-generator;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
## 内存模式示例
# spring.datasource.url=jdbc:h2:mem:testdb # 数据库驱动
spring.datasource.driver-class-name=org.h2.Driver # 用户名
spring.datasource.username=testdb # 密码
spring.datasource.password=test # 是否启用H2控制台
spring.h2.console.enabled=true # H2控制台的访问路径, 缺省是/h2-console
spring.h2.console.path=/h2-console # 是否允许远程访问H2
spring.h2.console.settings.web-allow-others=true

关于连接URL中的DB_CLOSE_ON_EXIT=FALSE

Don't Close a Database when the VM Exits.

By default, a database is closed when the last connection is closed. However, if it is never closed, the database is closed when the virtual machine exits normally, using a shutdown hook. In some situations, the database should not be closed in this case, for example because the database is still used at virtual machine shutdown (to store the shutdown process in the database for example). For those cases, the automatic closing of the database can be disabled in the database URL. The first connection (the one that is opening the database) needs to set the option in the database URL (it is not possible to change the setting afterwards).

2. h2的内存模式与本地模式

本地文件模式

spring.datasource.url=jdbc:h2:file:~/testdb

该例子中的~是用户目录。

内存模式

spring.datasource.url=jdbc:h2:mem:testdb

内存模式时,应用关闭则数据库同时关闭,数据库中的数据也就清空了。

3. H2的控制台

控制台界面如下:

端口号

访问H2的控制台时,URL中的端口号就是所在应用的端口号

路径

访问H2的控制台的路径后缀是spring.h2.console.path配置项的值,默认是/h2-console

Driver Class

org.h2.Driver

JDBC URL

填配置项spring.datasource.url的值

用户名密码

application.properties中配置的值对应。

Spring Boot 2.x 之 H2 数据库的更多相关文章

  1. 【spring boot】12.spring boot对多种不同类型数据库,多数据源配置使用

    2天时间,终于把spring boot下配置连接多种不同类型数据库,配置多数据源实现! ======================================================== ...

  2. Spring Boot中使用JdbcTemplate访问数据库

    本文介绍在Spring Boot基础下配置数据源和通过JdbcTemplate编写数据访问的示例. 数据源配置 在我们访问数据库的时候,需要先配置一个数据源,下面分别介绍一下几种不同的数据库配置方式. ...

  3. spring boot2.x中集成H2数据库

    H2数据库介绍  查看 在spring boot中集成 1.添加依赖 <dependency> <groupId>org.springframework.boot</gr ...

  4. 记录一次Spring boot 搭建框架连接Mysql数据库注解事务不回滚的故障

    搭建了一个新框架,使用了spring boot 替换以简化原来繁杂的spring配置,使用Spring注解管理事务,持久层使用mybatis. 连接mysql数据库完成项目的过程中发现不支持事务,因为 ...

  5. spring boot系列03--spring security (基于数据库)登录和权限控制(下)

    (接上篇) 后台 先说一下AuthConfig.java Spring Security的主要配置文件之一 AuthConfig 1 @Configuration 2 @EnableWebSecuri ...

  6. spring boot快速入门 4: jpa数据库操作 实现增删改查

    spring boot jpa逆向生成表 简单实例: 第一步:pom文件: <?xml version="1.0" encoding="UTF-8"?&g ...

  7. spring boot 集成mybatis连接oracle数据库

    1. POM文件添加依赖 <!-- Mybatis --> <dependency> <groupId>org.mybatis.spring.boot</gr ...

  8. 【Spring Boot】Spring Boot之使用AOP实现数据库多数据源自动切换

    一.添加maven坐标 <!-- aop --> <dependency> <groupId>org.springframework.boot</groupI ...

  9. Spring boot通过JPA访问MySQL数据库

    本文展示如何通过JPA访问MySQL数据库. JPA全称Java Persistence API,即Java持久化API,它为Java开发人员提供了一种对象/关系映射工具来管理Java应用中的关系数据 ...

随机推荐

  1. JavaGUI画笔工具的使用

    JavaGUI画笔工具的使用 package GUI; import java.awt.*; public class TestPaint { public static void main(Stri ...

  2. 【动画消消乐|CSS】083.纯CSS实现卡通齿轮效果

    前言 Hello!小伙伴! 非常感谢您阅读海轰的文章,倘若文中有错误的地方,欢迎您指出-   自我介绍 ଘ(੭ˊᵕˋ)੭ 昵称:海轰 标签:程序猿|C++选手|学生 简介:因C语言结识编程,随后转入计 ...

  3. 授予mysql的其他用户数据库的使用权限

    场景:不同的开发人员有不同的数据库的权限:也可适用于外包公司不同的开发权限. root用户登录数据库,命令行执行下面语句即可. grant select,delete,update,create,dr ...

  4. Guava入门第一章(Joiner)

    Guava是什么? Guava是一种基于开源的Java库,Google Guava源于2007年的"Google Collections Library".这个库是为了方便编码,并 ...

  5. NOIP 模拟 $12\; \text{简单的填数}$

    题解 一个纯的贪心,被我搞成 \(dp\) 了,最后把错解删掉了,骗了 \(10pts\) 考虑如何贪心,设置一种二元组 \((x,l)\),\(x\) 表示当前值,\(l\) 表示当前最长连续长度. ...

  6. 盘点 HashMap 的实现原理及面试题

    1.请你谈谈 HashMap 的工作原理如果被问到 HashMap 相关的问题,它的工作原理都会被作为面试的开场白,这个时候先装作若有所思的样子冷静一下.首先 HashMap 是基于 hashing ...

  7. 动态规划_C#

    参考网址:https://blog.csdn.net/lvcoc/article/details/104167648 先不管动态规划,先看斐波那契数列 斐波那契数列:F1=Fn-1+Fn-2 分别用递 ...

  8. Vue实现在前端导出Excel 方法2

    也可以去看下我的方法1:https://www.cnblogs.com/yingyigongzi/p/10915382.html ----------------------------------- ...

  9. springboot开启矩阵传参MatrixVariable

    /** *   根据 URI 规范 RFC 3986 中 URL 的定义,路径片段中可以可以包含键值对. * 规范中没对对应的术语.一般 "URL 路径参数" 可以被应用,尽管更加 ...

  10. 使用 antd 的 form 组件来自定义提交的数据格式

    最近使用antd UI 的表单提交数据,数据里面有的是数组,有的是对象.提交的时候还要去校验参数,让人非常头疼.在我仔细看完文档之后,发现 antd 的 form 组件做的非常不错,这些需求通通不是问 ...