Springboot 的 Flyway 实现对于 sqlserver 失败,错误函数“sp_getapplock”需要参数“@LockMode”,但未提供该参数

问题描述 投票:0回答:1

尝试为多个数据库的 spring-boot 应用程序添加 Flyway 迁移功能。

flyway 版本 - 10.1.0
春季启动 - 3.2.0

我正在尝试根据配置的数据源引入并支持多个数据库的迁移。 对于oracle和postgre来说,创建flyway_schema_history表并执行迁移工作正常 然而对于 SQL Server 来说它失败了。 下面是我的 Maven pom 片段

       <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>10.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-database-postgresql</artifactId>
            <version>$10.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-database-oracle</artifactId>
            <version>10.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-sqlserver</artifactId>
            <version>10.2.0</version>
        </dependency>
        <!-- Postgres -->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.6.0</version>
        </dependency>
        <!-- Oracle -->
        <dependency>
            <groupId>com.oracle.ojdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>19.3.0.0</version>
        </dependency>
        <!-- MSSQL -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>12.5.0.jre11-preview</version>
        </dependency>

我收到以下错误

Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: Unable to acquire SQL Server application lock
---------------------------------------------
SQL State  : S0004
Error Code : 201
Message    : Procedure or function 'sp_getapplock' expects parameter '@LockMode', which was not supplied.

                at org.flywaydb.database.sqlserver.SQLServerApplicationLockTemplate.execute(SQLServerApplicationLockTemplate.java:63)
                at org.flywaydb.database.sqlserver.SQLServerConnection.lock(SQLServerConnection.java:93)
                at org.flywaydb.core.internal.schemahistory.JdbcTableSchemaHistory.create(JdbcTableSchemaHistory.java:104)
                at org.flywaydb.core.Flyway.lambda$migrate$0(Flyway.java:199)
                at org.flywaydb.core.FlywayExecutor.execute(FlywayExecutor.java:215)
                at org.flywaydb.core.Flyway.migrate(Flyway.java:147)
                at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1822)
                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1771)
                ... 136 more
        Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Procedure or function 'sp_getapplock' expects parameter '@LockMode', which was not supplied.
                at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:261)
                at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1730)
                at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:653)
                at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:572)
                at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7706)
                at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:4201)
                at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:289)
                at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:263)
                at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:549)
                at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
                at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
                at org.flywaydb.core.internal.jdbc.JdbcTemplate.execute(JdbcTemplate.java:190)
                at org.flywaydb.database.sqlserver.SQLServerApplicationLockTemplate.execute(SQLServerApplicationLockTemplate

我尝试将 Flyway-sqlserver 更新到最新的 10.2.0,已清除我的 .m2 中的任何依赖项冲突。

我可以清楚地看到在 SQLServerApplicationLockTemplate 类中,当它尝试获取锁时

        this.jdbcTemplate.execute("EXEC sp_getapplock @Resource = ?, @LockTimeout='3600000', @LockMode = 'Exclusive', @LockOwner = 'Session'", new Object[]{this.lockName});

@LockMode 作为 Exclusive 传递,但仍然遇到相同的错误。

已经经历过

过程或函数“sp_getapplock”需要参数“@LockMode”,但未提供该参数

感谢您的任何建议和/或帮助

sql-server spring-boot migration flyway
1个回答
0
投票

问题是由

mssql-jdbc
引起的。回滚到版本
12.4.0.jre11
,一切都会好起来的。

© www.soinside.com 2019 - 2024. All rights reserved.