Maven:运行测试时无法拾取配置文件属性

时间:2018-11-28 10:33:02

标签: java maven intellij-idea

在pom.xml中,我定义了一个属性:

 <profile>
            <id>local</id>
            <properties>
                <build.profile.id>local</build.profile.id>
                <serverBaseUrl>http://127.0.0.1:8080</serverBaseUrl>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>

在文件application-email.xml中引用了serverBaseUrl

<bean id="MailService" class="someclass">
        <property name="aurl" value="${serverBaseUrl}"/>

    </bean>

我希望在运行测试,使用IntelliJ IDEA或Maven测试时,可以自动从pom.xml中提取$ {serverBaseUrl}。但是,它不能像我期望的那样工作。

当不进行测试时,事情完全符合我的预期。

这是什么问题?默认情况下,运行测试时,maven或IntelliJ IDEA是否不会获取配置文件属性?运行测试时如何获取配置文件的属性?

当前,我有一个解决方法:在config.properties中定义serverBaseUrl=xxx,然后拾取该属性。我要避免这种情况。

1 个答案:

答案 0 :(得分:0)

这更像是在黑暗中拍摄,我无法测试。

resources的{​​{1}}部分中添加build标记:

pom.xml

我想您的<build> ..... <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> <includes> <include>application-email.xml</include> </includes> </testResource> </testResources> .... </build> application-email.xml文件夹中。

相关问题