Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将@ActiveProfiles与SPRING\u PROFILES\u ACTIVE一起使用_Java_Spring_Spring Boot_Testing_Continuous Integration - Fatal编程技术网

Java 将@ActiveProfiles与SPRING\u PROFILES\u ACTIVE一起使用

Java 将@ActiveProfiles与SPRING\u PROFILES\u ACTIVE一起使用,java,spring,spring-boot,testing,continuous-integration,Java,Spring,Spring Boot,Testing,Continuous Integration,在我的Spring Boot应用程序中,我有树型配置文件:默认配置文件、测试配置文件和持续集成配置文件 持续集成配置文件定义了一个可选的datasource.url 测试配置文件定义了一个替代的liquibase.change-log 默认配置文件为我的应用程序定义默认属性 当我在本地运行测试时,我使用IntellIJ运行它们 为了在本地激活测试配置文件,我在测试中添加了@ActiveProfiles(“test”)注释 当我从CI运行它们时,我添加了SPRING\u PROFILES\u A

在我的Spring Boot应用程序中,我有树型配置文件:默认配置文件、测试配置文件和持续集成配置文件

持续集成配置文件定义了一个可选的datasource.url

测试配置文件定义了一个替代的liquibase.change-log

默认配置文件为我的应用程序定义默认属性

当我在本地运行测试时,我使用IntellIJ运行它们

为了在本地激活测试配置文件,我在测试中添加了
@ActiveProfiles(“test”)
注释

当我从CI运行它们时,我添加了
SPRING\u PROFILES\u ACTIVE
env变量,如下所示:

SPRING_PROFILES_ACTIVE=ci,test gradle integrationTest 
但是ci配置文件被Spring Boot忽略


如果我删除
@ActiveProfiles(“test”)
注释,我的CI工作得很好,但是我无法使用IntelliJ轻松运行我的测试。

当您将
@ActiveProfiles(“test”)
添加到测试类时,您正在覆盖由
SPRING\u profiles\u active
环境变量设置的活动配置文件定义

  • 一个选项是将“ci”配置文件添加到测试类执行中:

     @ActiveProfiles({"test", "ci"})
    
  • 如果不希望为本地/IDE测试执行激活“ci”,另一个选项是删除
    @ActiveProfiles
    注释,并在测试的IDE运行配置中使用
    -Dspring.profiles.active=test

  • 但是,如果您想在所有测试中激活概要文件“test”,只需删除
    @ActiveProfiles
    注释,从env var CI作业定义中删除“test”,然后将以下行添加到test/resources文件夹中的application.properties/yaml。(如果您还没有test/resources/application.properties,请知道它会覆盖main/resources/application.properties。)

  •  spring.profiles.include = test