【问题标题】:Is there a way to tell gradle which profiles should be used for the tests?有没有办法告诉 gradle 哪些配置文件应该用于测试?
【发布时间】:2017-01-19 19:12:51
【问题描述】:

我使用 yml 配置文件模式application-{default,dev,production}.yml

为了定义应用程序将使用哪个配置,我修复了环境SPRING_PROFILES_ACTIVE=dev,所以当 spring 应用程序运行时,它会选择正确的配置。

我现在有两个问题:

  1. ./gradlew build 命令也运行测试命令,测试需要像应用程序启动时一样具有正确的配置。
  2. 我的 jenkins 无权访问数据库,单元测试不断失败。

问:

  1. 构建命令是否按顺序尝试所有数据源?有没有办法指定 spring boot 活动配置文件?
  2. 还有其他不同的方法可以从 jenkins 在生产环境中部署 spring-boots 应用程序吗?
  3. 除了

    之外,有没有人有解决方法
    ./gradlew -x test build
    

    这不是我想要的。

    不要将@ActiveProfile("dev") 添加到我的测试中,因为这需要修改源代码。

【问题讨论】:

    标签: spring gradle docker spring-boot build


    【解决方案1】:

    只需创建多个属性文件。例如:
    应用程序.properties
    应用程序-test.properties
    应用程序生产.properties


    根据配置文件和
    提供不同的属性 您可以在下面指定 在你的 gradle.build 文件中加载哪个配置文件

    def profile = "test"
    bootRun {
     args = ["--spring.profiles.active="+profile]
    }
    

    将以下代码放在gradle文件的末尾

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      • 2011-07-28
      • 2023-03-26
      • 2016-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多