Spring Boot 2.x 之 H2 数据库
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 数据库的更多相关文章
- 【spring boot】12.spring boot对多种不同类型数据库,多数据源配置使用
2天时间,终于把spring boot下配置连接多种不同类型数据库,配置多数据源实现! ======================================================== ...
- Spring Boot中使用JdbcTemplate访问数据库
本文介绍在Spring Boot基础下配置数据源和通过JdbcTemplate编写数据访问的示例. 数据源配置 在我们访问数据库的时候,需要先配置一个数据源,下面分别介绍一下几种不同的数据库配置方式. ...
- spring boot2.x中集成H2数据库
H2数据库介绍 查看 在spring boot中集成 1.添加依赖 <dependency> <groupId>org.springframework.boot</gr ...
- 记录一次Spring boot 搭建框架连接Mysql数据库注解事务不回滚的故障
搭建了一个新框架,使用了spring boot 替换以简化原来繁杂的spring配置,使用Spring注解管理事务,持久层使用mybatis. 连接mysql数据库完成项目的过程中发现不支持事务,因为 ...
- spring boot系列03--spring security (基于数据库)登录和权限控制(下)
(接上篇) 后台 先说一下AuthConfig.java Spring Security的主要配置文件之一 AuthConfig 1 @Configuration 2 @EnableWebSecuri ...
- spring boot快速入门 4: jpa数据库操作 实现增删改查
spring boot jpa逆向生成表 简单实例: 第一步:pom文件: <?xml version="1.0" encoding="UTF-8"?&g ...
- spring boot 集成mybatis连接oracle数据库
1. POM文件添加依赖 <!-- Mybatis --> <dependency> <groupId>org.mybatis.spring.boot</gr ...
- 【Spring Boot】Spring Boot之使用AOP实现数据库多数据源自动切换
一.添加maven坐标 <!-- aop --> <dependency> <groupId>org.springframework.boot</groupI ...
- Spring boot通过JPA访问MySQL数据库
本文展示如何通过JPA访问MySQL数据库. JPA全称Java Persistence API,即Java持久化API,它为Java开发人员提供了一种对象/关系映射工具来管理Java应用中的关系数据 ...
随机推荐
- Android面试6家一线大厂,这个问题是必问!
年后面了六家大厂,每家都会问的一个问题就是Android的消息机制!可见Android的消息机制是多么重要! 消息机制之所以这么重要是因为Android应用程序是通过消息来驱动的,Android某种意 ...
- 线程强制执行_join
线程强制执行_join Join合并线程,待此线程执行完成后,再执行其他线程,其他线程阻塞 可以想象为插队 测试案例: package multithreading; // 测试Join方法 // 想 ...
- Java协程编程之Loom项目尝鲜
前提 之前很长一段时间关注JDK协程库的开发进度,但是前一段时间比较忙很少去查看OpenJDK官网的内容.Java协程项目Loom(因为项目还在开发阶段,OpenJDK给出的官网https://ope ...
- Spring系列之HikariCP连接池
上两篇文章,我们讲到了Spring中如何配置单数据源和多数据源,配置数据源的时候,连接池有很多选择,在SpringBoot 1.0中使用的是Tomcat的DataSource,在SpringBoot ...
- NOIP 模拟 $14\; \text{队长快跑}$
题解 \(by\;zj\varphi\) 一道很妙的 \(dp\) 题,方程状态不好设置,细节也不少 看到数据范围,直接想离散化 设 \(f_{i,j}\) 表示处理完前 \(i\) 个水晶,其中摧毁 ...
- 查看linux系统是物理机还是虚拟机
物理机,返回机器型号 [root@laocalhost ~]# dmidecode -s system-product-name S910-X31E 虚拟机 [root@dev01-188 ~]# d ...
- GIT基础篇,配置账号及命令查看以及帮助命令
提交用户名和邮件地址 1 安装完Git首先要设置你的用户名称与邮件地址.每一个Git的提交都会使用这些信息,并且它会写入到你的每一次提交中. 2 git config --global user. ...
- .net core signalR 服务端强制中断用户连接
.net core signalR 服务端断开连接 { } { } *:first-child { } *:last-child { } { } { } { } { } { } { } { } { } ...
- JAVA中的clone方法剖析
原文出自:http://blog.csdn.net/shootyou/article/details/3945221 java中也有这么一个概念,它可以让我们很方便的"制造"出一个 ...
- [题解] SPOJ GSS1 - Can you answer these queries I
[题解] SPOJ GSS1 - Can you answer these queries I · 题目大意 要求维护一段长度为 \(n\) 的静态序列的区间最大子段和. 有 \(m\) 次询问,每次 ...