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

Spring3.2.1+Flyway10.4.1升级后Flyway实例化报错:Name must not be null

Spring 3.2.1 + Flyway 10.4.1 升级后「Name must not be null」异常解决(PostgreSQL 15.x)

升级Spring从2.7.x到3.2.1,同时将Flyway从8.5升级到10.4.1后,出现如下异常:

Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception with message: Name must not be null

针对PostgreSQL 15.x环境,可通过以下步骤解决:

一、调整application.properties配置

# Spring Flyway 配置
spring.flyway.enabled=true
spring.flyway.baselineOnMigrate=true
spring.flyway.validateOnMigrate=true
spring.flyway.locations=classpath:db/migration

# 数据源配置
spring.datasource.jdbc-url=jdbc:postgresql://localhost:5432/database-name
spring.datasource.url=jdbc:postgresql://localhost:5432/database-name
spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.username=<<username>>
spring.datasource.password=<<password>>
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect

配置调整说明:

  • 将Hibernate方言从PostgreSQL10Dialect改为PostgreSQLDialect
  • 新增spring.datasource.jdbc-url配置(替代原spring.datasource.url,保留原配置做兼容)
  • 确保JDBC URL使用jdbc:postgresql协议,而非旧的postgre协议

二、更新Maven依赖

Flyway 10+版本需要单独引入对应数据库的支持依赖,此前仅需flyway-core即可。更新后的依赖如下:

<!-- Flyway 核心及数据库支持依赖 -->
<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>10.4.1</version>
</dependency>
<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-database-postgresql</artifactId>
    <version>10.4.1</version>
    <scope>runtime</scope>
</dependency>
<!-- 若无需支持SQL Server可移除以下依赖 -->
<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-sqlserver</artifactId>
    <version>10.4.1</version>
</dependency>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 09:35:36