查看“Spring Boot 集成 H2”的源代码
←
Spring Boot 集成 H2
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
=== 添加依赖 === <syntaxhighlight lang="xml"> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.13</version> </parent> <dependencies> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> </dependencies> </syntaxhighlight> === 配置 === <syntaxhighlight lang="yaml"> spring: datasource: url: jdbc:h2:mem:testdb driver-class-name: org.h2.Driver schema: classpath:db/schema-h2.sql username: root password: test h2: console: enabled: true path: /h2-console </syntaxhighlight>默认还是使用了 Hikari 作为数据库连接池; H2 可以选择将数据存储在内存还是磁盘上,用 <code>spring.datasource.url</code> 配置: * <code>jdbc:h2:mem:testdb</code> 这种就是内存,然后库名是 testdb * <code>jdbc:h2:file:/path/to/db/file</code> 这种就是文件 和 Spring Boot 内置的 Web 容器一起用的时候,可以使用 H2 的 Web 控制台,但需要先启用: <code>spring.h2.console.enabled=true</code>,否则访问就会 404 <code>spring.h2.console.path</code> 配置控制台,默认就是 /h2-console 其他常见配置: https://docs.spring.io/spring-boot/docs/2.4.13/reference/html/appendix-application-properties.html#spring.h2.console.enabled
返回至
Spring Boot 集成 H2
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
Spring Boot 2 零基础入门
Spring Cloud
Spring Boot
设计模式之禅
VUE
Vuex
Maven
算法
技能树
Wireshark
IntelliJ IDEA
ElasticSearch
VirtualBox
软考
正则表达式
程序员精讲
软件设计师精讲
初级程序员 历年真题
C
SQL
Java
FFmpeg
Redis
Kafka
MySQL
Spring
Docker
JMeter
Apache
Linux
Windows
Git
ZooKeeper
设计模式
Python
MyBatis
软件
数学
PHP
IntelliJ IDEA
CS基础知识
网络
项目
未分类
MediaWiki
镜像
问题
健身
国债
英语
烹饪
常见术语
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息