spring-boot - Spring Boot 数据源和 h2 数据库路径
问题描述
在我的 Spring Boot 应用程序中,我正在尝试配置 H2 数据库文件夹的路径。我想通过以下路径放置它:
/home/public/h2
像这样的配置:
# Datasource
spring.datasource.url=jdbc:h2:file:/home/public/h2
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
导致以下错误:
Caused by: org.h2.jdbc.JdbcSQLException: A file path that is implicitly relative to the current working directory is not allowed in the database URL "jdbc:h2:file:/home/public/h2". Use an absolute path, ~/name, ./name, or the baseDir setting instead. [90011-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357) ~[h2-1.4.197.jar:1.4.197]
我也试过spring.datasource.url=jdbc:h2:file:~/home/public/h2
,但它不起作用。
我在做什么错以及如何正确配置路径?
解决方案
请尝试使用jdbc:h2:./name
(显式相对路径),或
将系统属性设置h2.implicitRelativePath
为true(以防止此检查)。
对于 Windows,绝对路径还需要包含驱动器("C:/...")
。
h2.implicitRelativePath=true
spring.datasource.url=jdbc:h2:~/home/public/h2
或者
h2.implicitRelativePath=true
spring.datasource.url=jdbc:h2:file:~/home/public/h2
有关更多详细信息,请查看此处...
推荐阅读
- jmeter - Beanshell 断言
- vue.js - Vue - 在多页面环境中导入组件
- spring - 如何从控制器调用服务
- php - Codeigniter 控制器方法 404 错误
- python - 返回 Gensim Word2vec 中单词的排名
- python-3.x - askopenfilename() 禁用编辑 tkinter 条目
- python - 如何将数据框更改为多索引数据框
- excel - 运行时错误“1004”:对象 _Workbook 的方法 SaveAs 失败
- kubernetes - 如何修复 Kubernetes NodeUnderDiskPressure 错误?
- java - 当类实现该接口时,该类是否继承了在接口中声明的抽象内部类?