kre*_*nkz 3 maven flyway spring-boot
我在我的 Spring-Boot 项目中使用 Flyway(在带有 Maven 的 Eclipse 中)
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我遇到了一些有趣的问题。
整个事情运行良好,直到我迁移失败(由于模式语法中的拼写错误)。我尝试运行 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!
Run Code Online (Sandbox Code Playgroud)
现在,我不明白的奇怪的事情是,如果我将所有信息添加到 pom.xml 中
<properties>
<flyway.user>databaseUser</flyway.user>
<flyway.password>databasePassword</flyway.password>
<flyway.url>urlAddress</flyway.url>
</properties>
Run Code Online (Sandbox Code Playgroud)
它建立了。但是如果我将信息添加到我的 application.properties 文件中
spring.flyway.user=databaseUser
spring.flyway.password=databasePassword
spring.flyway.url=urlAddress
Run Code Online (Sandbox Code Playgroud)
出现相同的错误消息。
根据Baedlung Database Migrations with Flyway(他们使用 Flyway Maven 插件),在哪里配置 Flyway 并不重要。所以我想知道我是否应该切换到flyway-maven-plugin?我真的很想将所有配置都放在 .properties 文件中。
第一件事:通过 Java 编程代码进行数据库迁移的 Flyway-core。
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>7.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
import org.flywaydb.core.Flyway;
...
Flyway flyway = Flyway.configure().dataSource(url, user, password).load();
flyway.migrate();
// Start the rest of the application (incl. Hibernate)
...
Run Code Online (Sandbox Code Playgroud)
第二件事:Maven 目标的 Flyway 插件,通过命令行运行。
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.0.3</version>
</plugin>
Run Code Online (Sandbox Code Playgroud)
和
mvn clean flyway:migrate -Dflyway.configFile=myFlywayConfig.properties
Run Code Online (Sandbox Code Playgroud)
您可以选择第一件事或第二件事,取决于您的喜好(通过Java代码或命令进行数据库迁移)
| 归档时间: |
|
| 查看次数: |
3372 次 |
| 最近记录: |