flyway.properties文件不起作用,作为pom.xml配置的替代方案。

huangapple go评论94阅读模式
英文:

flyway.properties file not working as pom.xml configuration alternative

问题

我需要设置Flyway迁移,但我不想将密码和用户名放在pom.xml中。我创建了flyway.properties文件,但它不起作用,我得到以下错误信息:

Failed to execute goal org.flywaydb:flyway-maven-plugin:6.5.1:clean (default-cli) on project entesting: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!

flyway.properties文件与pom.xml位于同一目录下,内容如下:

flyway.user=sa
flyway.password=passwordForThis
flyway.url=jdbc:sqlserver://172.23.176.144;database=DB_Name
flyway.locations=filesystem:src/main/resources/db/migration
flyway.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver

pom.xml中的Flyway插件配置如下:

<plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>6.5.1</version>
    <configuration>
        <url>jdbc:sqlserver://172.23.176.144;database=DB_Name</url>
        <user>sa</user>
        <password>passwordForThis</password>
    </configuration>
</plugin>

总结一下,我不想在pom.xml中添加密码、用户名等信息(这样可以工作),我希望它们在flyway.properties文件中。

英文:

I need to set flyway migration and I don't want to put password and username in pom.xml, I created flyway.properties file, but it's not working, I'm getting this error

Failed to execute goal org.flywaydb:flyway-maven-plugin:6.5.1:clean (default-cli) on project entesting: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password!

flyway.properties file is in same directory as pom.xml

flyway.user=sa
flyway.password=passwordForThis
flyway.url=jdbc:sqlserver://172.23.176.144;database=DB_Name
flyway.locations=filesystem:src/main/resources/db/migration
flyway.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver

pom.xml flyway plugin config:

        &lt;plugin&gt;
            &lt;groupId&gt;org.flywaydb&lt;/groupId&gt;
            &lt;artifactId&gt;flyway-maven-plugin&lt;/artifactId&gt;
            &lt;version&gt;6.5.1&lt;/version&gt;
            &lt;configuration&gt;
                &lt;url&gt;jdbc:sqlserver://172.23.176.144;database=DB_Name&lt;/url&gt;
                &lt;user&gt;sa&lt;/user&gt;
                &lt;password&gt;passwordForThis&lt;/password&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;

To summarize I don't want to add password, username etc. in pom.xml(that works), I want it to be in flyway.propeties.

答案1

得分: 2

Flyway可以以多种方式进行配置,不仅可以直接将其放入maven pom.xml中。请参阅配置maven插件上的文档。

你展示的属性文件的内容看起来像是flyway.conf文件的内容。如果存在的话,Flyway会搜索并自动加载<user-home>/flyway.conf配置文件。

还可以将Flyway指向一个或多个附加的配置文件。这可以通过提供System属性flyway.configFiles来实现,如下所示:

mvn -Dflyway.configFiles=path/to/myAlternativeConfig.conf flyway:migrate

请参阅https://flywaydb.org/documentation/maven/#config-files了解更多信息。

此外,Maven settings.xml文件也可以用于存储数据库用户和密码:

<settings>
    <servers>
        <server>
            <!-- 默认情况下,Flyway将查找id为'flyway-db'的服务器 -->
            <!-- 可以通过配置'serverId'属性进行自定义 -->
            <id>flyway-db</id>
            <username>myUser</username>
            <password>mySecretPwd</password>
        </server>
    </servers>
</settings>
英文:

Flyway can be configured in a number of ways beyond directly putting it into the maven pom.xml. See documentation on configuring the maven plugin

The contents of the properties file you showed looks like the contents of a flyway.conf file.
Flyway will search for and automatically load the &lt;user-home&gt;/flyway.conf config file if present.

It is also possible to point Flyway at one or more additional config files. This is achieved by supplying the System property flyway.configFiles as follows:

mvn -Dflyway.configFiles=path/to/myAlternativeConfig.conf flyway:migrate

See https://flywaydb.org/documentation/maven/#config-files for more information.

Alternatively for storing the database user and password, Maven settings.xml files can also be used:

&lt;settings&gt;
   &lt;servers&gt;
       &lt;server&gt;
           &lt;!-- By default Flyway will look for the server with the id &#39;flyway-db&#39; --&gt;
           &lt;!-- This can be customized by configuring the &#39;serverId&#39; property --&gt;
           &lt;id&gt;flyway-db&lt;/id&gt;
           &lt;username&gt;myUser&lt;/username&gt;
           &lt;password&gt;mySecretPwd&lt;/password&gt;
       &lt;/server&gt;
   &lt;/servers&gt;
&lt;/settings&gt;

huangapple
  • 本文由 发表于 2020年7月22日 21:43:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63035625.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定