1、2 集成flyway
修改pom.xml,添加相关依赖
<!-- flyway -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>6.2.4</version>
</dependency>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>6.2.4</version>
// 属性也可另写一个配置文件进行配置
<configuration>
<driver>com.mysql.cj.jdbc.Driver</driver>
<url>
jdbc:mysql://localhost:3306/adamalluseUnicode=true&characterEncoding=utf8&useSSL=false
</url>
<user>root</user>
<password>csy546065250.</password>
<baselineOnMigrate>true</baselineOnMigrate>
<locations>
<location>db/migration</location>
</locations>
<table>flyway_schema_history</table>
<sqlMigrationPrefix>V</sqlMigrationPrefix>
<!--<undoSqlMigrationPrefix>U</undoSqlMigrationPrefix>-->
<repeatableSqlMigrationPrefix>R</repeatableSqlMigrationPrefix>
<sqlMigrationSeparator>__</sqlMigrationSeparator>
<sqlMigrationSuffixes>
<migrationSuffix>.sql</migrationSuffix>
</sqlMigrationSuffixes>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
遇到的问题:无法找到db/migration路径及无法执行sql语句
产生原因:flyway会默认在·(default: filesystem:src/main/resources/db/migration)
下寻找SQL语句,如果自己配置了location,需配置成classpath:db/migration
,不能配成db/migration
解决办法:删掉配置文件中设置的查找路径或正确配置路径
注意:无法执行SQL语句还有可能是因为编译文件未重新编译,重新编译即可;