我尝试使用以下抽象类在 src/test/resources 类路径中加载 spring 配置文件:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:/applicationContext.xml"})
public class BaseIntegrationTests {
}
我在 src/test/resources 中有 applicationContext.xml 文件,但 spring 无法加载它。
谢谢。
准确来说,是内容测试输出目录 (target/test-classes
)是在类路径上,而不是src/test/resources
。但资源下src/test/resources
被复制到测试输出目录 by the resources:testResources http://maven.apache.org/plugins/maven-resources-plugin/testResources-mojo.html目标(默认绑定到process-test-resources
phase).
话虽如此,您的代码看起来不错,并且测试源代码的资源应该在运行测试时由您的 IDE 或 Maven 复制,因此应该在类路径上可用。所以一定还有其他问题。我可以看到你的类是集成测试的基类。你在你的pom中配置了什么奇特的东西吗?你能展示一下吗?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)