在我的Spring Boot项目中,我需要使用SQLite数据库.我已经成功地设置了SQLite数据库,如下所示:
依赖关系:
implementation("org.xerial:sqlite-jdbc:3.42.0.0")
implementation("org.hibernate.orm:hibernate-community-dialects")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
Application.yml
spring:
datasource:
url: jdbc:sqlite:file:myDb.db?cache=shared
username: root
password: root
正如您在上面看到的,我使用的是on disk SQLite数据库,数据库文件是myDb.db
.
我还创建了数据源Bean:
@Bean
public DataSource dataSource() {
final DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(props.getDriverClassName());
dataSource.setUrl(props.getUrl());
dataSource.setUsername(props.getUsername());
dataSource.setPassword(props.getPassword());
return dataSource;
}
我验证了这个SQLite数据库设置是否工作,因为当我开始运行我的项目时,实体类的关联数据库表已在数据库中成功创建.
Next, I try to setup Flyway as below:个
我包括了依赖关系:
implementation("org.flywaydb:flyway-core:8.5.11")
In Application.yml
, I added:
spring:
...
flyway:
baseline-on-migrate: true
schemas: myDb
enabled: true
url: jdbc:sqlite:file:myDb.db?cache=shared
user: root
password: root
validate-on-migrate: true
locations: "classpath:db/migration"
我还在src/main/resources/
下创建了目录 /db/migration
目录
但当开始运行项目时,I end up with error:%
Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: Unable to check whether table "myDb"."flyway_schema_history" exists`
我确实理解在SQLite中没有"数据库模式"的概念,所以我也try 手动创建表flyway_schema_history
,然后开始运行项目,但我仍然收到相同的错误.
我怎样才能让Flyway+SQLite在春靴中工作?我遗漏了什么?
(我怀疑这是一个数据库连接问题,因为在我设置Flyway之前,项目可以成功地建立连接,并基于JPA实体创建表.或者是我错过了Flyway的某些特定于SQLite的配置来为Flyway建立数据库连接?我不确定...)