spring从2.7.x升级到3.2.1版本后 并将 Flyway 从 8.5 升级到版本 10.4.1,我收到了如标题所示的异常:
无法实例化[org.flywaydb.core.Flyway]:工厂方法“flyway”抛出异常并显示消息:名称不能为空
我正在使用 postgresql 版本 15.x
我设法解决问题如下:
我添加或更改应用程序属性:
#spring-flyway settings:
spring.flyway.enabled=true
spring.flyway.baselineOnMigrate=true
spring.flyway.validateOnMigrate=true
spring.flyway.locations=classpath:db/migration
#spring.datasource settings:
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
我必须添加新的依赖项: 支持适当数据库所需的信息可以在存储库或此处找到: 就我而言https://documentation.red-gate.com/flyway/flyway-cli-and-api/supported-databases
<!--flyway-->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>10.4.1</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-sqlserver</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>
以前只需要flyway-core
我添加或更改应用程序属性:
#spring-flyway settings:
spring.flyway.enabled=true
spring.flyway.baselineOnMigrate=true
spring.flyway.validateOnMigrate=true
spring.flyway.locations=classpath:db/migration
#spring.datasource settings:
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
注意我从 PostgreSQL10Dialect 更改为 PostgreSQLDialect 的方言
2a。请注意 spring.datasource.jdbc-url 而不是 spring.datasource.url=
2b。和 jdbc:postgresql 而不是 postgre
我必须添加新的依赖项:支持适当数据库所需的依赖项可以在存储库或此处找到: 就我而言https://documentation.red-gate.com/flyway/flyway-cli-and-api/supported-databases
<!--flyway--> <dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>10.4.1</version> </dependency> <dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-sqlserver</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>
以前只需要flyway-core