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. 2579页阿里P8Android学习笔记在互联网上火了,完整版开放下载

    笔记作者:来自于阿里P8级大神: Mark 笔记特点:条理清晰,理论+实战+源码,含图像化表示更加易懂. 内容概要:Android 相关,性能优化,Java 相关,Kotlin 相关,网络相关,插件化 ...

  2. Linux中的账号权限管理

    一.用户账号和组账号概述 Linux基于用户身份对资源访问进行控制 1.1.用户账号 超级用户:root 用户是 Linux 操作系统中默认的超级用户账号,对本主机拥有最高的权限.系统中超级用户是唯一 ...

  3. JCE加密和解密 bouncycastle

    https://blog.csdn.net/weixin_43935907/article/details/89155617 https://blog.csdn.net/qq_29583513/art ...

  4. MySQL慢查询及开启慢查询

    一.简介 开启慢查询日志,可以让MySQL记录下查询超过指定时间的语句,通过定位分析性能的瓶颈,才能更好的优化数据库系统的性能. 二.参数说明 slow_query_log 慢查询开启状态 slow_ ...

  5. minio设置永久访问链接

    1.通过minio分享的链接只能支持7天. 解决方案是设置对应的bucket 可通过路径直接访问.(必须通过minio client才能设置下载策略) wget https://dl.min.io/c ...

  6. DVWA(九):File Upload 全等级文件上传

    File Upload 文件上传,通常是由于对上传文件的类型没有进行严格的过滤.限制造成的,一般思路是 通过上传木马获取服务器的webshell(通过网络端口对网站服务器某种程度上的操作权限 也叫网站 ...

  7. 题解 party?

    传送门 挺遗憾的一个题 考场上想到的思路是题解的退化版,可以有71pts(赛时以为只有20pts),但因为这一场的策略原因没有打-- 首先发现颜色种类数很少,可以直接bitset上树剖维护,炸不了空间 ...

  8. 题解 graph

    传送门 一道做了巨久,不过确实很好的题 发现不定边权极难处理,所以就不会 感觉和这题有点像,但还是不会 但发现题面里有个地方很套路 要求有哪些点/边最终可以满足最短/最小,比如这样或这样的题,考虑凸包 ...

  9. noip模拟6(T2更新

    由于蒟弱目前还没调出T1和T2,所以先写T3和T4.(T1T2更完辣! update in 6.12 07:19 T3 大佬 题目描述: 他发现katarina大佬真是太强了,于是就学习了一下kata ...

  10. JavaScript(Node.js)+ Selenium 实现淘宝抢单

    JavaScript(Node.js)+ Selenium 淘宝抢单 为了买买买我也是拼了,看了一点selenium的资料,随便写的. 程序写的比较烂,但是够我自己用了,望各路大牛指教. 使用说明: ...