是否有一种方法可以在Eclipse中获得JUnit测试(特别是使用SpringJUnit4ClassRunner)来使用来自src/main/resources和src/test/resources的资源
Maven的尽是火插件可以做到这一点,但是从Eclipse运行一个特定的单元测试并不能做到这一点。
我已经在src/main/resources/spring-config/中加载了Spring,我想要“覆盖”两个特定的文件。我已经在src/test/resources/spring-config/中放置了这些特定于测试的重写,当通过Maven运行单元测试时,每件事情都是有效的。当我从Eclipse中运行JUnit测试时,只有测试文件可用,毫不奇怪,我的上下文无法加载。
更新
显示配置测试上下文的Spring类在使用通配符时无法从src/main/resources/中找到资源,但如果我显式指定它们,则会找到它们。
src/main/resources/ 找不到的东西
@ContextConfiguration(locations = {"classpath:/spring-config/*.xml"})src/main/resources/ 是否从中找到指定的文件
@ContextConfiguration(locations = {"classpath:/spring-config/*.xml",
"classpath:/spring-config/app-aws.xml"})发布于 2012-03-09 14:12:53
这实际上是Spring的一个限制,而不是JUnit。详情请参见http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/resources.html#resources-wildcards-in-path-other-stuff。
解决方案是将Spring配置文件放在包中而不是根包中。
https://stackoverflow.com/questions/9632710
复制相似问题