如何使用配置文件中的文件系统设置飞行路径配置以进行测试?

How to set flyway path configuration for test using filesystem in configuration file?

我已经使用配置文件为 Local 设置了飞路任务,并连接到我的任务,例如

tasks.create<FlywayMigrateTask>("migrateLocal") {
    configFiles = arrayOf("config/flyway/flyway.conf")
}

此任务运行正常并且脚本执行良好,但是当我尝试使用定义配置路径的应用程序-TEST.yaml 文件进行 运行 集成测试时,出现以下错误

Flyway failed to initialize: none of the following migration scripts locations could be found:

    - classpath:db/migration

问题是我不想在测试文件夹中重新定义相同的配置,我想使用我的应用程序从文件系统中引用它们-TEST.yaml 在测试包的资源文件夹中像这样

flyway:
    schemas: public
    locations: filesystem:doc/flyway/migrations,filesystem:config/flyway/archive,filesystem:config/flyway/post_migrations

如果我尝试这样做,当我 运行 单个测试时,我得到相同的 Flyway 无法初始化,事实上上下文无法加载

java.lang.IllegalStateException: Failed to load ApplicationContext

任何帮助将不胜感激

对于任何试图设置类似东西的人,你必须用

注释集成测试
@ActiveProfiles("TEST")

"TEST" 是配置文件 ("application-TEST.yaml")。

之后一切正常。

我通过在 src/main/resources 项目的文件夹中创建另一个名为 db 的文件夹来修复该错误,该文件夹又包含另一个名为 migration 的文件夹,我将脚本放在那里用于创建 table my_table。我在 application.properties 文件和 flyway 的标记 spring.flyway.schemas 中声明的架构将添加 my_table 和另一个 table flyway_schema_history.