无法打开Spring JUnit ContextConfiguration类路径资源
我正在gradle项目中使用最新版本的SpringBoot(SpringBootStarterWeb和test)。我以前使用的这个旧的单元测试已经不起作用了 XML上下文文件位于src/test/resources/myTestContext.XML下。但是,当我尝试在Eclipse(mars 4.5)中作为Junit测试运行此测试时,出现了以下错误无法打开Spring JUnit ContextConfiguration类路径资源,spring,junit,spring-boot,spring-test,Spring,Junit,Spring Boot,Spring Test,我正在gradle项目中使用最新版本的SpringBoot(SpringBootStarterWeb和test)。我以前使用的这个旧的单元测试已经不起作用了 XML上下文文件位于src/test/resources/myTestContext.XML下。但是,当我尝试在Eclipse(mars 4.5)中作为Junit测试运行此测试时,出现了以下错误 src/test/resources在您的类路径中吗?在eclipse中,如果我转到project->properties->java构建路径,我
src/test/resources
在您的类路径中吗?在eclipse中,如果我转到project->properties->java构建路径,我会看到列出了src/test/resources。您是否在没有“/”的情况下尝试过它?删除起始/并添加类路径:
@ContextConfiguration(locations={"/myTestContext.xml"})
public class MyTest extends AbstractJUnit4SpringContextTests{
....
Caused by: java.io.FileNotFoundException: class path resource [myTestContext.xml]
cannot be opened because it does not exist at
org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172) ~[spring-core-4.1.7.RELEASE.jar:4.1.7.RELEASE]