简体   繁体   English

Flyway-maven-plugin如何从Spring Boot application.yml中读取设置

[英]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&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;connectionCollation=utf8_unicode_ci&amp;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.

相关问题 在Spring Boot中从application.yml文件读取编号 - Read number from application.yml file in spring boot 如何从 spring-boot 应用程序中的 application.yml 文件中读取属性 - How to read properties from application.yml file in spring-boot application 如何使用Spring Boot从application.yml读取变量并在Kotlin测试中使用它 - How to read variable from application.yml with spring boot and use it in kotlin test 如何将 application.yml 中的 map 注入 Spring 引导中的字段? - How to inject a map from application.yml into a field in Spring Boot? flyway-maven-plugin:如何一起执行多个数据库配置? - flyway-maven-plugin: how to execute multiple database configurations together? 在 application.yml 中访问 Maven 属性“developers”(Spring Boot) - Access Maven property “developers” in application.yml (Spring Boot) spring boot中application.yml是按什么顺序读取的? - In what order are application.yml read in spring boot? Spring Boot - 从 application.yml 和 application.properties 注入 - Spring Boot - inject from application.yml and application.properties Spring Boot - 无法从实例化对象中读取 application.yml 值 - Spring Boot - Cannot read application.yml values from instantiated object 无法从 Java Spring Boot 项目的 application.yml 文件中读取用户定义的类列表 - Unable to read list of user defined class from application.yml file in a Java Spring Boot project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM