转载

springboot H2数据库持久化配置

每次编一些简单的应用总是要创建表,安装数据库非常繁琐 这里可以通过 H2 数据库的持久化功能来达到和Mysql一样功能,且不需要安装数据库非常便利
spring:
 datasource:
 driver-class-name: org.h2.Driver
 url: jdbc:h2:file:/www/${spring.application.name}/db
 # Windows
 # url: jdbc:h2:file:C:/data/sample/${spring.application.name}/db;
 #内存数据配置
 #spring.datasource.url=jdbc:h2:mem:testdb
 username: sa
 password:
 jpa:
 hibernate:
 ddl-auto: update
 database-platform: org.hibernate.dialect.H2Dialect
 h2:
 console:
 path: /h2
 enabled: true
 settings:
 web-allow-others: true
把url 修改文件类型,然后设置spring.jpa.hibernate.ddl-auto=update h2 的访问配置根据喜好来吧
参考 [1]. How to configure spring-boot to use file based H2 database . Avinash . https://stackoverflow.com/questions/37903105/how-to-configure-spring-boot-to-use-file-based-h2-database    
正文到此结束
Loading...