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

Flyway与Spring Boot整合出现AbstractMethodError问题求助

Flyway与Spring Boot整合报错解决方案

问题描述

整合Flyway与Spring Boot时启动报错,错误栈如下:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.AbstractMethodError: Receiver class org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension does not define or inherit an implementation of the resolved method 'abstract void extractParametersFromConfiguration(java.util.Map)' of interface org.flywaydb.core.extensibility.ConfigurationExtension.
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:633)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1519)
    ... 73 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.AbstractMethodError: Receiver class org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension does not define or inherit an implementation of the resolved method 'abstract void extractParametersFromConfiguration(java.util.Map)' of interface org.flywaydb.core.extensibility.ConfigurationExtension.
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648)
    ... 88 common frames omitted
Caused by: java.lang.AbstractMethodError: Receiver class org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension does not define or inherit an implementation of the resolved method 'abstract void extractParametersFromConfiguration(java.util.Map)' of interface org.flywaydb.core.extensibility.ConfigurationExtension.
    at org.flywaydb.core.api.configuration.ClassicConfiguration.configure(ClassicConfiguration.java:1373)
    at org.flywaydb.core.api.configuration.ClassicConfiguration.configureFromConfigurationProviders(ClassicConfiguration.java:1669)
    at org.flywaydb.core.api.configuration.ClassicConfiguration.configure(ClassicConfiguration.java:1345)
    at org.flywaydb.core.api.configuration.ClassicConfiguration.<init>(ClassicConfiguration.java:412)
    at org.flywaydb.core.Flyway.<init>(Flyway.java:100)
    at org.flywaydb.core.api.configuration.FluentConfiguration.load(FluentConfiguration.java:59)
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:126)
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 89 common frames omitted

使用的组件版本

  • Flyway:10.20.1(最新版本),Maven依赖配置:
<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>10.20.1</version>
</dependency>

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-database-postgresql</artifactId>
    <version>10.20.1</version>
    <scope>runtime</scope>
</dependency>
  • Spring Boot:2.7.18
  • 数据库:PostgreSQL 16.4
  • 操作系统:Windows 11

应用配置

spring:
  datasource:
    hikari:
      connection-test-query: SELECT 1
      maximum-pool-size: 5
      minimum-idle: 2
      pool-name: HikariPool-Postgres
    url: jdbc:postgresql://localhost:5432/xxx_db?currentSchema=public
    driver-class-name: org.postgresql.Driver
    username: xxx
    password: xxx
  jpa:
    show-sql: false
  flyway:
    enabled: true

解决方案

这个错误是版本兼容性问题导致的:Spring Boot 2.7.x的自动配置模块与Flyway 10.x的API不兼容,Flyway 10.x对ConfigurationExtension接口新增了extractParametersFromConfiguration方法,但Spring Boot 2.7.x的Flyway自动配置逻辑并未适配这个变更,同时PostgreSQL数据库扩展也出现了API实现不匹配的情况。

解决办法有两个:

方案1:降级Flyway到Spring Boot 2.7.x兼容的版本

Spring Boot 2.7.18官方推荐的Flyway版本是8.5.13,修改Maven依赖如下:

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
</dependency>

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-database-postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

注:去掉版本号,让Spring Boot的依赖管理自动引入兼容版本,避免手动版本冲突。如果需要指定版本,直接写8.5.13即可。

方案2:升级Spring Boot到支持Flyway 10.x的版本

Flyway 10.x需要Spring Boot 3.0及以上版本支持,如果你可以升级Spring Boot,建议升级到3.2.x或最新稳定版,这样就能直接使用Flyway 10.x的功能,同时兼容PostgreSQL 16.x。

验证:修改版本后,清理Maven缓存(mvn clean install -U),重新启动应用即可正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 15:02:01