h2使用

#  http://localhost:8080/h2-console
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
#进行该配置后,每次启动程序,程序都会运行resources/schema.sql文件,对数据库的结构进行操作,相当于新建一个表。
spring.datasource.schema=classpath:schema.sql
#进行该配置后,每次启动程序,程序都会运行resources/data.sql文件,对数据库的数据操作,相当于往表中插入数据。
spring.datasource.data=classpath:data.sql


# 数据库类型声明
spring.jpa.database=H2
# 是否开启查询语句在控制台打印
spring.jpa.show-sql=true
# Hibernate ddl auto (create, create-drop, update),这里的设置为update很重要,不然初始化时就一张空表,data.sql的数据进不去。
#spring.jpa.hibernate.ddl-auto=update
# Naming strategy
#spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
#开启h2控制台功能和访问地址。
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

#### h2新版本自增id有问题
  <properties>
    <java.version>1.8</java.version>
    <!-- H2 1.4.197 breaks auto-incrementing identity columns for some reason -->
    <h2.version>1.4.196</h2.version>
</properties>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
原文地址:https://www.cnblogs.com/fly-book/p/13111631.html