Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 如何将选定的Maven配置文件传递到Spring配置文件?_Java_Spring_Maven - Fatal编程技术网

Java 如何将选定的Maven配置文件传递到Spring配置文件?

Java 如何将选定的Maven配置文件传递到Spring配置文件?,java,spring,maven,Java,Spring,Maven,我有3个maven项目A、B、C。A是B的父项目,B是C的父项目。所有配置文件都在项目A的pom.xml中定义 在项目C中,我试图根据所选配置文件在spring测试上下文中选择属性文件(在src/test/resources下)。对于回归测试,我们有两个属性文件: application-test-local.properties 应用程序测试属性 在我们的windows开发系统上,选定的配置文件将是“本地”的,并相应地在服务器上。选择“本地”配置文件时,应在测试Spring上下文中使用应用

我有3个maven项目A、B、C。A是B的父项目,B是C的父项目。所有配置文件都在项目A的
pom.xml
中定义

在项目C中,我试图根据所选配置文件在spring测试上下文中选择属性文件(在src/test/resources下)。对于回归测试,我们有两个属性文件:

  • application-test-local.properties
  • 应用程序测试属性
在我们的windows开发系统上,选定的配置文件将是“本地”的,并相应地在服务器上。选择“本地”配置文件时,应在测试Spring上下文中使用
应用程序测试本地.properties
,否则应使用
应用程序测试.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>

码头工人
本地服务器
地方的
发展
dev01
质量保证
dqa01
戳
prod01

默认情况下,Maven测试使用。您可以在Maven配置文件中将Spring配置文件声明为属性:

<profile>
  <id>docker</id>
  <properties>
    <spring.profiles.active>docker</spring.profiles.active>
  </properties>
</profile>

码头工人
码头工人
然后使用
配置将其传递给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>

org.apache.maven.plugins
maven surefire插件
-Dspring.profiles.active=@{spring.profiles.active}@{argLine}
请注意,
@{…}
语法:

由于版本2.17使用了argLine的另一种语法,@{…}允许在插件执行时延迟替换属性,因此其他插件修改过的属性将被正确拾取


回归测试、单元测试或集成测试是什么意思?如何通过surefire插件调用它?最后,为什么您有两组测试用例,您不想在测试阶段测试所有东西吗?