【问题标题】:Springboot & maven - Changing datasource configuration with maven commandSpringboot & maven - 使用 maven 命令更改数据源配置
【发布时间】:2021-02-16 09:53:20
【问题描述】:

在我的项目(springboot、maven)中,我使用@TestPropertySource({"classpath:flyway.properties", "/queries/test.properties"}) 注释的测试来覆盖与我的数据源相关的一些属性。 我使用mvn clean test 命令运行测试。

现在我想在我的 Jenkins 管道中添加一个新阶段,以便对两个不同的数据源执行测试。

当我运行 maven 命令时,有没有办法覆盖我的文件 (test.properties) 中的值?或者我可以使用两个不同的文件与弹簧配置文件或类似的东西:

@TestPropertySource({"classpath:flyway.properties", "/queries/test-${env/profile}.properties"})

任何见解将不胜感激。干杯!

【问题讨论】:

    标签: java spring maven testing datasource


    【解决方案1】:

    您可以拥有不同的配置文件并通过运行按需激活正确的配置文件:

    mvn -DargLine="-Dspring.profiles.active=myProfile" clean test

    【讨论】:

    • 感谢您的回答,但配置文件如何帮助我管理我的 2 个文件(例如 test-db1.propertiestest-db2.properties我>)?我正在寻找一种方法来更改 @TestPropertySource 注释中的文件,基于我将作为 maven 命令的参数传递的值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-02
    • 1970-01-01
    • 2010-12-24
    • 2014-10-01
    • 2018-12-10
    • 2013-07-21
    • 2021-02-06
    相关资源
    最近更新 更多