Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala Flyway在sbt中找不到我的迁移文件_Scala_Slick_Flyway - Fatal编程技术网

Scala Flyway在sbt中找不到我的迁移文件

Scala Flyway在sbt中找不到我的迁移文件,scala,slick,flyway,Scala,Slick,Flyway,我正在尝试应用迁移来支持测试中的H2数据库,我的文件夹结构是: src - test -- resources --- db ---- migration ----- V1_0__init_tables.sql 我已将配置设置为指向classpath:db/migrationvia Flyway .configure() .locations(migrateLocations) .dataSource(url, use

我正在尝试应用迁移来支持测试中的H2数据库,我的文件夹结构是:

src
- test
-- resources
--- db
---- migration
----- V1_0__init_tables.sql
我已将配置设置为指向
classpath:db/migration
via

        Flyway
          .configure()
          .locations(migrateLocations)
          .dataSource(url, user, password)
          .load()
          .migrate() 
当我运行测试时,我得到以下输出

2018-11-29 16:14:14,351 DEBUG [ScalaTest-run] slf4j.Slf4jLog (Slf4jLog.java:45) - Scanning for classpath resources at 'classpath:db/migration' ...
2018-11-29 16:14:14,351 DEBUG [ScalaTest-run] slf4j.Slf4jLog (Slf4jLog.java:45) - Determining location urls for classpath:db/migration using ClassLoader sun.misc.Launcher$AppClassLoader@18b4aac2 ...
2018-11-29 16:14:14,420 WARN  [ScalaTest-run] slf4j.Slf4jLog (Slf4jLog.java:53) - Unable to resolve location classpath:db/migration
2018-11-29 16:14:14,421 DEBUG [ScalaTest-run] slf4j.Slf4jLog (Slf4jLog.java:45) - Scanning for classes at classpath:db/migration
这让我很困惑,为什么
Flyway
找不到我的文件。据我所知,我已经按照医生的建议做了一切。我的测试最终失败了,因为我的表从未迁移过,因此
Slick
无法找到我的表


我的迁移文件中可能有错误,但我假设
Flyway
会对此进行某种记录?我没有看到类似的情况。

您是否有意将迁移文件放在
src/test/resources
下?无论如何,我认为Flyway不会在那里找到它们,因为您的
classpath:db/migration
很可能引用
src/main/resources
,而不是测试资源。
只需尝试将迁移文件放在主资源下。

Spring Boot 2将默认设置为
Spring.flyway.locations=classpath:db/migration
,并指向
src/main/resources/db/migration
文件夹,而不考虑运行单元测试。您可以将SQL文件目录放入文件系统,然后设置
spring.flyway.locations=filesystem:path/to/yourdir
可以在项目文件夹中的任何位置添加SQL迁移脚本,例如在
prj_root/resources/migrations
中(其中
resources
src
文件夹的同级)。 要将其作为资源嵌入,它需要在
build.sbt
中使用此文件:

Compile+=baseDirectory.value/“resources”中的UnmanagedResourceDirectory

然后在迁移代码中指定此位置:
Flyway.configure().locations(“/migrations”)…

在idea中将这个新的资源目录标记为
resources Root
也是有意义的,但它不是必需的,只是一种美化