首页 > 解决方案 > 尝试在本地使用 H2 文件进行存储时忽略 Spring 数据源配置

问题描述

我正在尝试使用一些 REST API 和存储创建简单的 Spring Boot 应用程序以在本地运行。我使用Spring 初始化程序初始化了应用程序,现在尝试配置数据库以在本地进行测试,因此我将这些设置添加到application.properties

spring.datasource.url=jdbc:h2:file:~/data/my_app_db
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=usr
spring.datasource.password=123
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
spring.h2.console.path=/h2/console
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false

据我了解,这应该配置我的 h2 控制台路径和文件数据库路径,但在日志中我得到以下输出:

INFO 22917 --- [  restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:4bcaeb11-32f9-442d-9e8f-439608ffd960'

我无法理解我错过了什么。这不应该工作吗?如果不是,为什么?

标签: springkotlinh2application.properties

解决方案


推荐阅读