Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Flyway maven插件如何从spring boot application.yml读取设置_Java_Spring Boot_Database Migration_Flyway - Fatal编程技术网

Java Flyway maven插件如何从spring boot application.yml读取设置

Java Flyway maven插件如何从spring boot application.yml读取设置,java,spring-boot,database-migration,flyway,Java,Spring Boot,Database Migration,Flyway,在我的SpringBoot项目中,我想使用FlywayMaven插件。 我的pom: 据我所知,使用mvn flyway:info时,我需要一些插件来读取我的application.yml。或者有其他方法吗?我的理解是,如果您使用带有Spring Boot的Flyway,则不使用Flyway maven插件 编辑:当您需要直接使用DB对Flyway的模式表进行修改时,使用Flyway CLI有一个位置。例如,init现有数据库或clean测试项目 这些是当前设置,可以通过在Flyway的应用程序

在我的SpringBoot项目中,我想使用FlywayMaven插件。 我的pom:


据我所知,使用mvn flyway:info时,我需要一些插件来读取我的application.yml。或者有其他方法吗?

我的理解是,如果您使用带有Spring Boot的Flyway,则不使用Flyway maven插件

编辑:当您需要直接使用DB对Flyway的模式表进行修改时,使用Flyway CLI有一个位置。例如,
init
现有数据库或
clean
测试项目

这些是当前设置,可以通过在Flyway的
应用程序.properties
中设置属性来执行

# FLYWAY (FlywayProperties)
flyway.check-location=false # check that migration scripts location exists
flyway.locations=classpath:db/migration # locations of migrations scripts
flyway.schemas= # schemas to update
flyway.init-version= 1 # version to start migration
flyway.init-sqls= # SQL statements to execute to initialize a connection immediately after obtaining it
flyway.sql-migration-prefix=V
flyway.sql-migration-suffix=.sql
flyway.enabled=true
flyway.url= # JDBC url if you want Flyway to create its own DataSource
flyway.user= # JDBC username if you want Flyway to create its own DataSource
flyway.password= # JDBC password if you want Flyway to create its own DataSource
YAML版本:

flyway:
    check-location: false
    locations: classpath:db/migration
    ....

如果您需要进一步定制,您可能需要编写一个
@Bean
来进一步定制Flyway如何与您的应用程序交互。

要从pom中读取
*.yml
属性,您应该使用我的
src/main/resources/application.properties中包含以下内容

flyway.url=jdbc:sqlserver://localhost:1433
flyway.user=james_hetfield
flyway.password=MetaLLic@

spring.datasource.url=${flyway.url}
spring.datasource.user=${flyway.user}
spring.datasource.password=${flyway.password}
然后我从命令行运行迁移,如下所示

mvn -Dflyway.configFiles=src/main/resources/application.properties flyway:migrate

你为什么要使用这个插件?Spring Boot负责为您执行flyway,无需在maven文件中执行。不使用CLI或maven插件,无法运行“info、validate、repair”和其他功能。另外,我没有使用application.properties。我有application.yml.You是正确的,除非您修改Spring Boot的配置。考虑
init
现有数据库的工作流。飞道CLI将是伟大的。然后让Spring Boot处理迁移。Spring Boot中的Flyway支持YAML。您有没有一个例子?假设您正在谈论如何在YAML中使用Flyway
flyway.url=jdbc:sqlserver://localhost:1433
flyway.user=james_hetfield
flyway.password=MetaLLic@

spring.datasource.url=${flyway.url}
spring.datasource.user=${flyway.user}
spring.datasource.password=${flyway.password}
mvn -Dflyway.configFiles=src/main/resources/application.properties flyway:migrate