我正在尝试在我的 Spring Boot 应用程序中使用 H2 数据库。下面是 application.properties 文件。
# Local db filestore: in your home folder
spring.datasource.url=jdbc:h2:file:~/db/rd_light.db;DB_CLOSE_ON_EXIT=FALSE;IFEXISTS=TRUE;DB_CLOSE_DELAY=-1;
# h2 defaults:
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
# Use "create" or "create-drop" when you wish to recreate database on restart; use
# "update" or "validate" when data is to be kept.
spring.jpa.hibernate.ddl-auto = update
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.flyway.enabled=true
spring.flyway.url=jdbc:h2:file:~/db/rd_light.db
spring.flyway.user=sa
spring.flyway.password=
spring.flyway.locations=classpath:db/migration
当我运行该应用程序时,出现以下错误。
2018-06-11 12:19:53.160 ERROR 19455 --- [JavaFX-Launcher] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
org.h2.jdbc.JdbcSQLException: Database "/home/administrator/db/rd_light.db" not found [90013-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357) ~[h2-1.4.197.jar:1.4.197]
at org.h2.message.DbException.get(DbException.java:179) ~[h2-1.4.197.jar:1.4.197]
我尝试手动创建文件,但仍然遇到相同的错误。 即使我尝试使用内存数据库而不是基于文件的数据库,我也会收到相同的错误。
最佳答案
在spring.datasource.url
中删除标志IFEXISTS=TRUE;
。
如果该标志设置为 true,则仅当数据库存在时才会建立连接。有关标志的引用,请参阅 http://www.h2database.com/html/features.html#database_only_if_exists
关于spring-boot - 未找到 H2 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50791915/