[英]Flyway-maven-plugin how to read the settings from spring boot application.yml
In my Spring Boot project I want to use flyway-maven-plugin. 在我的Spring Boot项目中,我想使用flyway-maven-plugin。 My pom:
我的pom:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.1</version>
<configuration>
<url>jdbc:mysql://localhost:3306/my_database?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&connectionCollation=utf8_unicode_ci&characterSetResults=UTF-8</url>
<user>root</user>
<password>${spring.datasource.password}</password>
</configuration>
</plugin>
And here is my application.yml 这是我的application.yml
spring:
profiles.active: default
---
spring:
profiles: default
spring.datasource:
password: root
As I understood to use mvn flyway:info
I need some plugin which will read my application.yml. 据我了解使用
mvn flyway:info
我需要一些插件来读取我的application.yml。 Or maybe there is another way? 也许还有另一种方法?
My understanding is that if you are using Flyway with Spring Boot you do not use the flyway-maven plugin. 我的理解是,如果您将Flyway与Spring Boot结合使用,则不要使用flyway-maven插件。
EDIT: Using Flyway CLI has a place when you need to work with the DB directly to make modifications to Flyway's schema table. 编辑:当您需要直接与数据库一起对Flyway的架构表进行修改时,使用Flyway CLI就有了一个地方。 An example would be to
init
an existing DB or clean
a test project. 一个示例是
init
现有数据库或clean
测试项目。
These are the current settings that can be performed out of the box by setting properties within the application.properties
for Flyway. 这些是当前设置,可以通过在Flyway的
application.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 version: YAML版本:
flyway:
check-location: false
locations: classpath:db/migration
....
If you need further customization you may need to write a @Bean
to further customize how Flyway interacts with your application. 如果需要进一步的自定义,则可能需要编写
@Bean
来进一步自定义@Bean
与应用程序的交互方式。
I have the following in my src/main/resources/application.properties
我的
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}
And then I run the migrations from the command-line as follows 然后我从命令行运行迁移,如下所示
mvn -Dflyway.configFiles=src/main/resources/application.properties flyway:migrate
要从pom读取*.yml
属性,您应该使用https://github.com/aadnk/yaml-properties-plugin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.