数据库地址配置 jdbc:h2:<mem|file|tcp>:<dbname>|{dbFilePath} 1.内存数据库: jdbc:h2:mem:DbName 2. 文件数据库 jdbc:h2:file:{FilePath} ./{path}/{fileName} 当前程序的根目录创建目录和数据库文件 ~/{path}/{fileName} 当前用户根目录创建目录和数据库文件 C:/{path}/{fileName} 指定目录 file 可以不写 ,默认 3. 远程数据库 jdbc:h2:tcp://<{IP|HostName}>[:{port}]/[{Path}]<{DbName}> Spring Boot整合H2数据库 -H2可以嵌入使用,也可以独立使用 -H2提供了Web控制台 -H2与Spring Boot可以完美集成 依赖导入 ????????<dependency> ????????????<groupId>com.h2database</groupId> ????????????<artifactId>h2</artifactId> ????????????<scope>runtime</scope> ????????</dependency> H2 配置 application.properties 1. 简单配置 spring.datasource.url=jdbc:h2:mem:testdb spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.jpa.database-platform=org.hibernate.dialect.H2Dialect 2. 数据持久化配置 # temporary data storage spring.datasource.url = jdbc:h2:file:/data/sample spring.datasource.url = jdbc:h2:file:C:/data/sample (Windows only) 3. 在初始化时创建表和插入数据。 在/src/main/resources/ 放置: schema.sql?– 创建表 data.sql? - 插入数据 4. 控制台 spring.h2.console.enabled=true spring.h2.console.path=/h2 5. 其他配置 默认都是false 是否允许调试输出 spring.h2.console.settings.trace=false 允许远端访问 spring.h2.console.settings.web-allow-others=false https://howtodoinjava.com/spring-boot2/h2-database-example/ https://docs.spring.io/spring-boot/docs/2.1.x/reference/html/howto-database-initialization.html