1

我正在使用 Maven 配置文件运行 JUnit 测试。

Maven 配置文件看起来是这样的:

<profile>
    <id>someProfile</id>
    <properties>
        ...
        <some.param>some_value</some.param>
        ... 
    </properties>
</profile>

弹簧上下文文件(testContext.xml):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       ...
       xmlns:p="http://www.springframework.org/schema/p"
       ...
       xsi:schemaLocation="...">
    <bean id="someBean" class="someClass"
          scope="singleton"
          autowire="byName"
          init-method="init"
          p:someBeanParam="${some.param}"/>
</beans>

测试课是这样开始的:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/testContext.xml"})
@Configurable
...

运行 maven 后,我看到 testContext.xml 没有改变 - p:someBeanParam仍然有值${some.param}

你能告诉我这里有什么问题以及如何解决吗?

先感谢您。

4

1 回答 1

1

像这样启用资源过滤

<project>
  ...
  <build>
     ...
     <resources>
         ...
         <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
         </resource>
         ...
     </resources>
     <testResources>
         ...
         <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
         </testResource>
         ...
     </testResources>
     ...
  </build>
  ....

为每个配置文件定义变量以及何时不使用配置文件。

有关Maven 资源插件页面的更多信息。

于 2013-05-24T11:44:47.200 回答