Spring Boot : H2 数据库

作者: 聪明的奇瑞 | 来源:发表于2018-01-22 10:33 被阅读1300次

H2 数据库

  • H2 数据库是一个轻量级的数据库,它十分适合作为内嵌式数据库,它采用纯 Java 编写,因此不受到平台限制,它提供了一个十分方便的 Web 控制台用于操作和管理数据库
  • Spring Boot 在引入 H2 依赖后会自动连接 H2 testdb 数据库,要查看连接的信息需要将日志级别改为 DEBUG
logging.level.org.hibernate=DEBUG  

Spring Boot 整合 H2

引入 H2 依赖

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>

配置 H2 数据库

spring:
  h2:
    console:
      path: /h2-console   # h2 web consloe 路径
      enabled: true       # 开启 h2 web consloe,默认为 false
      settings:
        web-allow-others: true    #允许远程访问 h2 web consloe
  datasource:
    username: sa
    url: jdbc:h2:mem:test
    driver-class-name:  org.h2.Driver

通过 URL:http://localhost:8080/h2-console/ 访问数据库管理界面

WX20180122-102715@2x.png

相关文章

网友评论

    本文标题:Spring Boot : H2 数据库

    本文链接:https://www.haomeiwen.com/subject/jzflaxtx.html