记录今天在Spring boot项目中使用Flyway时遇到的版本冲突问题
1. 报错信息
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:65)
The following method did not exist:org.flywaydb.core.Flyway.migrate()
The method's class, org.flywaydb.core.Flyway, is available from the following locations:jar:file:/F:/Maven/LocalWarehouse/org/flywaydb/flyway-core/8.0.5/flyway-core-8.0.5.jar!/org/flywaydb/core/Flyway.class
It was loaded from the following location:file:/F:/Maven/LocalWarehouse/org/flywaydb/flyway-core/8.0.5/flyway-core-8.0.5.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.flywaydb.core.Flyway
2. 查看当前spring boot和flyway的版本
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>8.0.5</version>
</dependency>
3.解决方法
将flyway版本降级至5.2.1即可
4.总结
springboot2.x
pom文件
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.2.1</version>
</dependency>
配置文件
# 配置flyway
spring.flyway.baseline-on-migrate=true
spring.flyway.enabled=true
spring.flyway.locations=classpath:db/migration
spring.flyway.table=flyway_schema_history
springboot1.x
pom
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>4.2.0</version>
配置文件 (注意spring boot1.x 配置使用flyway开头)
# 配置flyway
flyway.baseline-on-migrate=true
flyway.enabled=true
flyway.locations=classpath:db/migration
flyway.table=flyway_schema_history