英文:
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:
<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>
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 <user-home>/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:
<settings>
<servers>
<server>
<!-- By default Flyway will look for the server with the id 'flyway-db' -->
<!-- This can be customized by configuring the 'serverId' property -->
<id>flyway-db</id>
<username>myUser</username>
<password>mySecretPwd</password>
</server>
</servers>
</settings>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论