从Eclipse运行Spring JUnit测试时,将/ src/main/resources添加到Classpath

Eng*_*_DJ 15 eclipse junit spring unit-testing maven

有没有办法在Eclipse中使用JUnit测试(特别是我正在使用SpringJUnit4ClassRunner)来使用src/main/resources以及来自的资源src/test/resources

Maven的surefire插件可以做到这一点,但是从Eclipse运行一个特定的单元测试却没有.

我有一个Spring配置加载,src/main/resources/spring-config/我想'覆盖'两个特定的文件.我已经放置了这些特定于测试的覆盖src/test/resources/spring-config/,并且当通过Maven eveerything运行单元测试时.当我从Eclipse运行JUnit测试时,只有测试文件可用,并且不出所料我的上下文无法加载.

更新

看来,配置测试上下文的Spring类src/main/resources/在使用通配符时无法找到资源,但如果我明确指定它们,则会找到它们.

找不到东西 src/main/resources/

@ContextConfiguration(locations = {"classpath:/spring-config/*.xml"})
Run Code Online (Sandbox Code Playgroud)

是否找到指定的文件src/main/resources/

@ContextConfiguration(locations = {"classpath:/spring-config/*.xml",
                                   "classpath:/spring-config/app-aws.xml"})
Run Code Online (Sandbox Code Playgroud)

Kkk*_*kev 7

这实际上是Spring的限制,而不是JUnit.有关详细信息,请参阅http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/resources.html#resources-wildcards-in-path-other-stuff.

解决方案是将Spring配置文件放在包中而不是根包中.