- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有3个maven项目A,B,C。A是B的父项目,B是C的父项目。所有配置文件都在项目的pom.xml
中定义A.
在项目 C 中,我尝试根据所选配置文件在 spring-test-context(在 src/test/resources 下)中选择属性文件。对于回归测试>,我们有 2 个属性文件:
在我们的 Windows 开发系统上,所选配置文件将是“本地”并相应地位于服务器上。当选择“本地”配置文件时,应在测试 Spring 上下文中使用 application-test-local.properties
,否则应使用 application-test.properties
。在项目C中,在spring-test-context.xml
中,我尝试过:
<beans profile="docker">
<util:properties id="metaDbProps" location="application-test-local.properties"/>
</beans>
<beans profile="default">
<util:properties id="metaDbProps" location="application-test.properties"/>
</beans>
但是,应用程序似乎无法将选定的 Maven 配置文件传递到 spring 配置文件,因为我正在尝试 “mvn clean test -Pdocker” 并且它总是从“<强>默认”配置文件。
知道如何修复以将 Maven 配置文件传递到 Spring 配置文件,以便它可以获取正确的属性文件吗?
为了便于理解,以下是项目 A 中配置文件的定义方式:
<profiles>
<!-- Windows development -->
<profile>
<id>docker</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>localhost</INSTALL_MACHINE_LIST>
<COPY_MODE>local</COPY_MODE>
</properties>
</profile>
<!-- Development -->
<profile>
<id>dev</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>dev01</INSTALL_MACHINE_LIST>
</properties>
</profile>
<!-- QA -->
<profile>
<id>qa</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>dqa01</INSTALL_MACHINE_LIST>
</properties>
</profile>
<!-- Production -->
<profile>
<id>prod</id>
<activation/>
<properties>
<INSTALL_MACHINE_LIST>prod01</INSTALL_MACHINE_LIST>
</properties>
</profile>
</profiles>
最佳答案
默认情况下,Maven 测试使用 Maven Surefire Plugin 运行。 。您可以将 Spring 配置文件声明为 Maven 配置文件中的属性:
<profile>
<id>docker</id>
<properties>
<spring.profiles.active>docker</spring.profiles.active>
</properties>
</profile>
然后使用 <argLine>
将其传递给 Surefire配置:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dspring.profiles.active=@{spring.profiles.active} @{argLine}</argLine>
</configuration>
</plugin>
</plugins>
</build>
请注意@{...}
语法:
Since the Version 2.17 using an alternate syntax for argLine, @{...} allows late replacement of properties when the plugin is executed, so properties that have been modified by other plugins will be picked up correctly
关于java - 如何将选定的 Maven 配置文件传递到 Spring 配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53215901/
我是一名优秀的程序员,十分优秀!