Flyway在jar文件中找不到迁移 [英] Flyway not finding the migrations in a jar file

查看:99
本文介绍了Flyway在jar文件中找不到迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在支持的许多应用程序中实现了Flyway,并且像梦一样运作。

I implemented Flyway in a number of applications I support and it worked like a dream.

但是,一旦我将应用程序部署到测试环境,迁移就会停止

However as soon as I deployed the applications to the test environment the migrations stopped working.

经过一番调查,我发现当迁移文件加载到jar文件中时,它们不是由Flyway定位的,而是当它们没有压缩时(例如我正在Eclipse中工作,或者如果我将jar提取到类路径中,它会按预期工作。

After some investigation I found that the migrations are not being located by Flyway when they are loaded into a jar file, but when they are not zipped up (like when I am working in Eclipse or if I extract the jar into the classpath) it works as expected.

由于应用程序的插件体系结构,我无法使用使用默认设置,并以此设置Flyway对象:

Due to the plugin architecture of the applications I am not in a position to use the "default" setting and as such am setting the Flyway object up like this:

Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setBaseDir("za/co/company/application/plugin1/db/migration");
flyway.setTable(tableName);
flyway.setBasePackage("za.co.company.application.plugin1.db.migration");
flyway.init();
flyway.migrate();

如果要解压缩jar文件,则sql文件位于:
za / co / company / application / db / migration

If one was to unzip the jar file the sql files would be located in: za/co/company/application/db/migration

如上所述,我知道迁移有效,只是当它们位于jar文件中时不起作用。
上面的代码执行得很好,只是没有发现要在迁移过程中运行的sql文件。

As mentioned I know the migrations work, just not when they are in the jar file. The code above executes perfectly, it's just that there are no sql files found to run as part of the migration.

尽管最初是使用flyway-core-开发的1.6我已经在1.6.1和1.7_SNAPSHOT发行版中尝试过(具有相同的负面结果),发现此处此处报告了类似的问题。

Although originaly developed using flyway-core-1.6 I have tried it (with the same negative results) with 1.6.1 and a 1.7_SNAPSHOT release I found here and here where a similar problem was reported.

编辑:其他信息

OS:Windows XP

JDK:1.7.0_04

DB:SQL Server 2005

通过bat文件从命令窗口直接运行。

OS: Windows XP
JDK: 1.7.0_04
DB: SQL Server 2005
Running straight from the command window via a bat file.

2012-06-27 15:50:05.855 main: flyway.migrate()
2012-06-27 15:50:05.886 Database: Microsoft SQL Server
2012-06-27 15:50:05.902 Schema: dbo
2012-06-27 15:50:05.902 Unable to find path for sql migrations: za\co\company\application\plugin1\db\migration
2012-06-27 15:50:05.918 Scanning URL: jar:file:/C:/Temp/lib/plugin1.jar!/za/co/company/application/plugin1/db/migration
2012-06-27 15:50:05.918 Filtering out resource: za/co/company/application/plugin1/db/migration/ (filename: )
2012-06-27 15:50:05.918 Filtering out resource: za/co/company/application/plugin1/db/migration/V1_1__Allows_cancelations.sql (filename: V1_1__Allows_cancelations.sql)
2012-06-27 15:50:05.918 Filtering out resource: za/co/company/application/plugin1/db/migration/V1__Base_version.sql (filename: V1__Base_version.sql)
2012-06-27 15:50:05.933 main: done Migrate.

我已确认我使用的是默认前缀(V)和后缀(.sql)。日志中提到的被过滤出的迁移文件的名称确实是我想要执行的迁移。

I have confirmed that I am using the default prefix (V) and suffix (.sql). And the names of the migration files mentioned in the log as being filtered out are indeed the migrations I would like to have performed.

编辑:更多信息。
我克隆了源存储库,并在将资源记录为被过滤掉之前获得了堆栈跟踪。

Still more info. I cloned the source repository and got a stack trace just before the resource was logged as being filtered out.

at com.googlecode.flyway.core.util.scanner.ClassPathScanner.filterResourceNames(ClassPathScanner.java:203)
at com.googlecode.flyway.core.util.scanner.ClassPathScanner.findResourceNames(ClassPathScanner.java:136)
at com.googlecode.flyway.core.util.scanner.ClassPathScanner.scanForClasses(ClassPathScanner.java:67)
at com.googlecode.flyway.core.migration.jdbc.JdbcMigrationResolver.resolveMigrations(JdbcMigrationResolver.java:51)
at com.googlecode.flyway.core.migration.CompositeMigrationResolver.collectMigrations(CompositeMigrationResolver.java:175)
at com.googlecode.flyway.core.migration.CompositeMigrationResolver.doFindAvailableMigrations(CompositeMigrationResolver.java:156)
at com.googlecode.flyway.core.migration.CompositeMigrationResolver.resolveMigrations(CompositeMigrationResolver.java:119)
at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:565)
at com.googlecode.flyway.core.Flyway$1.execute(Flyway.java:1)
at com.googlecode.flyway.core.Flyway.execute(Flyway.java:850)
at com.googlecode.flyway.core.Flyway.migrate(Flyway.java:561)

我已经确认迁移的唯一时间是在jar文件中找到迁移时。好像.sql迁移在jar文件中时甚至都没有扫描。

I have confirmed that the ONLY time the migrations are filtered out is when it finds them in a jar file. It is as if .sql migrations are not even scanned for when they re inside a jar file.

我还在四处寻找,并会相应地进行更新。

I am still poking around and will update accordingly.

编辑:源代码查询:
我对在其中仅玩了几个小时的Flyway源代码不太熟悉。 ..

Source Code query: I am not overly familiar with the Flyway source code I have been poking around in it for only a few hours...

SqlMigrationResolver类的resolveMigrations方法中的这段代码应该做什么?如果我从代码中将其删除,则SQLmigrations会完美地从Jar文件中加载,否则不会加载并记录警告。

What does this piece of code in the resolveMigrations method of the SqlMigrationResolver class supposed to do? If I remove it from the code the SQLmigrations load perfectly from the Jar file, if not they don't load and the warning is logged.

    if (StringUtils.hasText(normalizedBaseDir)) && !new ClassPathResource(normalizedBaseDir + "/").exists() ) {
        LOG.warn("Unable to find path for sql migrations: " + location);
        return migrations;
    }


推荐答案

尝试新发布的1.7。令人反感的陈述已被删除。

Try the newly released 1.7. The offending statement has been removed.

这篇关于Flyway在jar文件中找不到迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆