【问题标题】:Try to use flyway for multiple DB instances尝试对多个数据库实例使用 flyway
【发布时间】:2017-02-11 19:54:50
【问题描述】:

运行 Maven flyway-plugin

mvn flyway:migrate

使用此配置:

    <plugin>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-maven-plugin</artifactId>
      <version>4.0.3</version>
      <configuration>
        <driver>com.mysql.jdbc</driver>
        <url>jdbc:mysql://localhost:3306/schema2?createDatabaseIfNotExist=true</url>
        <user>root</user>
        <password>root</password>
      </configuration>
    </plugin>

我尝试在此解决方案中创建执行次数: How to use Flyway configuration to handle multiple databases

从一次执行开始:

    <plugin>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-maven-plugin</artifactId>
      <version>4.0.3</version>
      <executions>
        <execution>
          <id>migrate-database</id>
          <phase>compile</phase>
          <goals>
            <goal>migrate</goal>
          </goals>
          <configuration>
            <driver>com.mysql.jdbc</driver>
            <url>jdbc:mysql://localhost:3306/schema2?createDatabaseIfNotExist=true</url>
            <user>root</user>
            <password>root</password>
          </configuration>
        </execution>
      </executions>
    </plugin>

查看异常:

[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:4.0.3:migrate (default-cli) on project UrbanLife: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password! -> [Help 1]

看起来 flyway 看不到里面的配置 (有趣的是,在我之前提到的链接中,它有效)

请帮助通过 maven 创建 flyway multyDB 集成。

【问题讨论】:

  • 以下两个答案对我有帮助。现在我使用下一个命令: mvn flyway:migrate@migrate-MAINdatabase flyway:migrate@migrate-TESTdatabase
  • @markdsievers 为什么你从我的问题中删除了关于控制台的短语?新手比较容易理解。

标签: java maven execution flyway


【解决方案1】:

当您的 Maven 插件配置中有多个(或只有一个)&lt;execution&gt; 并尝试从命令行运行特定执行时,您需要通过执行 id 指定执行,就像您的情况一样

mvn flyway:migrate@migrate-database

另请参阅:How to execute maven plugin execution directly from command line?

最后,如果您希望特定执行成为默认执行,您可以将执行 id 指定为default-cli,如these maven docs 中所述。然后你可以简单地运行mvn flyway:migrate

【讨论】:

    【解决方案2】:

    驱动程序的 FQN 不正确,应该是 com.mysql.jdbc.Driver 或者您也可以简单地删除它,因为它会从 URL 中自动检测到。

    您还需要通过添加将驱动程序添加为插件的依赖项

    <plugin>
        ...
        <dependencies>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.39</version>
            </dependency>
        </dependencies>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 2018-12-23
      • 2012-10-01
      • 2012-10-13
      • 1970-01-01
      • 2013-03-06
      • 2018-10-11
      • 2019-05-21
      • 2017-09-11
      • 2011-11-10
      相关资源
      最近更新 更多