You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.1.0集成Flyway配置问题求助

问题解决:Spring Boot 3.1.0 + Flyway 版本不兼容导致方法找不到

问题根源

你遇到的NoSuchMethodError核心原因是版本兼容性不匹配:

  • Spring Boot 3.1.0的FlywayAutoConfiguration自动配置类会调用Flyway的oracleSqlplus(boolean)方法
  • 但你使用的Flyway 9.22.2已经移除了这个方法(Flyway 9.22.0版本开始删除了Oracle SQL*Plus相关的旧API)

解决方案

方案1:让Spring Boot自动管理Flyway版本(推荐)

Spring Boot的父依赖内置了所有兼容第三方库的版本,删掉Flyway依赖中的手动版本号即可自动适配:

修改后的完整POM(建议加上Spring Boot父依赖,这是Java Spring项目的最佳实践):

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <!-- 父依赖自动管理所有starter和第三方依赖的兼容版本 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.0</version>
        <relativePath/>
    </parent>

    <groupId>你的项目groupId</groupId>
    <artifactId>你的项目artifactId</artifactId>
    <version>你的项目版本</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
        </dependency>

        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-mysql</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

如果不想加父依赖,也可以通过dependencyManagement手动指定兼容的Flyway版本(Spring Boot 3.1.0默认适配Flyway 9.21.1):

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>9.21.1</version>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-mysql</artifactId>
            <version>9.21.1</version>
        </dependency>
    </dependencies>
</dependencyManagement>

方案2:升级Spring Boot版本

如果必须使用Flyway 9.22.2,可以把Spring Boot升级到3.1.2及以上版本——这些版本的自动配置代码已经适配了Flyway 9.22.x的API变更。

验证

修改完依赖后,执行mvn clean install刷新依赖,启动应用即可解决类路径不兼容的问题。你的application.properties配置无需修改。

内容的提问来源于stack exchange,提问作者Egor1705

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 20:25:26