Spring Boot数据源和h2数据库路径

问题描述 投票:0回答:2

在我的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但它不起作用。

我做错了什么以及如何正确配置路径?

spring-boot spring-data-jpa spring-data datasource h2
2个回答
1
投票

试试这个@Alexanoid ....

使用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

更多细节见这里... https://www.h2database.com/javadoc/org/h2/api/ErrorCode.html


0
投票

改变

spring.datasource.url =的jdbc:H2:文件:〜/家庭/公/ H2

至:

spring.datasource.url =的jdbc:H2:〜/家庭/公/ H2

© www.soinside.com 2019 - 2024. All rights reserved.