我想将我的 junit 测试和集成测试分开。所以我在 pom.xml 中为集成测试创建了一个单独的配置文件,如下所示:
<profiles>
<profile>
<id>integration-test</id>
<properties>
<test>IntegrationTestTrigger</test>
<spring.profiles.active>integration-test</spring.profiles.active>
</properties>
</profile>
<profiles>
当我运行 maven 命令 mvn test -Pintegration-test
时,它会选择上面显示的 <properties>
标记中定义的测试类IntegrationTestTrigger
。但它没有设置 spring.profiles.active
属性。所以测试从默认配置文件开始。它与 maven 命令 mvn test -Dtest=IntegrationTestTrigger -Dspring.profiles.active=integration-test
但根据我的组织 jenkins 设置,我需要为集成测试运行 mvn test -Pintegration-test
,因此我无法向 mvn 命令添加任何额外的环境变量
答案 0 :(得分:0)
中的属性用于替换资源文件夹中 .properties/.yml 文件中的属性。
示例:
application.yml:
spring:
profiles:
active: '@spring.profiles.active@'
pom.xml:
<profile>
<id>dev</id>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
</profile>
这里,@spring.profiles.active@
将在编译期间被 dev 替换(通过 maven-resources-plugin 插件)。 Spring Boot 在 spring-boot-starter-parent pom 中使用 @
作为资源分隔符。您可以通过更改以下属性将其更改为任何字符
//pom.xml
<project .....>
<properties>
<resource.delimiter>@</resource.delimiter>
...
</properties>
请参阅 https://github.com/gtiwari333/spring-boot-blog-app/blob/master/pom.xml#L436 以获取完整示例