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. Android开发三年,面了八家公司终于腾讯上岸,含泪整理面经

    在下2017年毕业,目前从事android开发工作已经3年多了,前段时间刚完成一次跳槽,面试了几家公司,将一些面试经验分享给大家,希望对大家有所帮助. 写在前面 这次跳槽总共是面了8家,(2小,4中, ...

  2. [源码解析] 机器学习参数服务器 Paracel (2)--------SSP控制协议实现

    [源码解析] 机器学习参数服务器 Paracel (2)-----SSP实现 目录 [源码解析] 机器学习参数服务器 Paracel (2)-----SSP实现 0x00 摘要 0x01 背景知识 1 ...

  3. 解决ftp登录问题:500 OOPS: cannot change directory:/home/xxx 500 OOPS: child died

    .personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...

  4. PHP变量覆盖漏洞整理

    昨天群里HW的大佬们都在传某某服终端检测响应平台edr存在大量RCE的洞 官网上关于EDR的介绍是这么写的 终端检测响应平台EDR,围绕终端资产安全生命周期,通过预防.防御.检测.响应赋予终端更为细致 ...

  5. Abp vNext 基础篇丨领域构建

    介绍 我们将通过例⼦介绍和解释⼀些显式规则.在实现领域驱动设计时,应该遵循这些规则并将其应⽤到解决⽅案中. 领域划分 首先我们先对比下Blog.Core和本次重构设计上的偏差,可以看到多了一个博客管理 ...

  6. 备战秋招之十大排序——O(nlogn)级排序算法

    时间复杂度O(nlogn)级排序算法 五.希尔排序 首批将时间复杂度降到 O(n^2) 以下的算法之一.虽然原始的希尔排序最坏时间复杂度仍然是O(n^2),但经过优化的希尔排序可以达到 O(n^{1. ...

  7. C#如何调用DOS命令

    在使用C#编辑过程中,通常需要利用外部命令来执行一些操作,从而完成特定的功能.下面小编就以利用C#调用DOS命令"Ver"显示系统版本号为例,给初学C#语言的网友讲解一下具体的调用 ...

  8. Socket 网络编程和IO模型

    最近做了一个织机数据采集的服务器程序. 结构也非常简单,织机上的嵌入式设备,会通过Tcp 不停的往服务器发送一些即时数据.织机大改有个几十台到几百台不定把 刨去业务,先分析一下网络层的大概情况.每台织 ...

  9. C++ 中的User a, User b=a 和User a, User b, b=a的区别

    #include <iostream>using namespace std;class User{ public: int age; int number; User() { cout ...

  10. 【转】互联网项目中mysql应该选什么事务隔离级别

    作者:孤独烟 转自:https://www.cnblogs.com/rjzheng/p/10510174.html 摘要 企业千万家,靠谱没几家.社招选错家,亲人两行泪. 祝大家金三银四跳槽顺利! 引 ...