我在我的Spring-Boot项目中使用Flyway (在带有maven的Eclipse中)
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>我遇到了一些有趣的问题。
整个过程运行得很好,直到我迁移失败(因为模式语法中的一个拼写错误)。我试着运行fly:repair,得到了这个错误
Failed to execute goal org.flywaydb:flyway-maven-plugin:6.4.1:repair (default-cli) on project springboot: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!现在,奇怪的是我不明白的是,如果我将所有信息添加到pom.xml中
<properties>
<flyway.user>databaseUser</flyway.user>
<flyway.password>databasePassword</flyway.password>
<flyway.url>urlAddress</flyway.url>
</properties>它会构建。但是如果我将信息添加到我的application.properties文件中
spring.flyway.user=databaseUser
spring.flyway.password=databasePassword
spring.flyway.url=urlAddress出现相同的错误信息。
根据Baedlung Database Migrations with Flyway的说法(他们使用的是Flyway Maven插件),在哪里配置Flyway并不重要。所以我想知道我是否应该切换到flyway-maven-plugin?我真的希望所有的配置都在.properties文件中。
发布于 2020-10-03 00:09:13
第一件事:通过Java编程代码实现数据库迁移的Flyway-core。
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>7.0.0</version>
</dependency>import org.flywaydb.core.Flyway;
...
Flyway flyway = Flyway.configure().dataSource(url, user, password).load();
flyway.migrate();
// Start the rest of the application (incl. Hibernate)
...第二件事:Flyway- Maven goal的插件,由命令行运行。
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0.3</version>
</plugin>和
mvn clean flyway:migrate -Dflyway.configFile=myFlywayConfig.properties您可以根据自己的喜好选择第一件事或第二件事(通过Java代码或命令进行数据库迁移)
https://stackoverflow.com/questions/64174158
复制相似问题