我的测试看上去像是
public class ITCache extends AbstractIntegrationTest {
@Test
public void readCache() {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
assertNotNull(applicationContext);
final SimpleCacheManager simpleCacheManager = (SimpleCacheManager) applicationContext.getBean("cacheManager");
System.out.println("cacheName:" + simpleCacheManager.getCacheNames().toString());
System.out.println(simpleCacheManager.getCache("genders").toString());
}
}我使用maven-cargo插件部署我的项目,可以查看内容并找到applicationContext.xml。
➜ comma git:(S120297) ✗ jar -tvf integration/target/cargo/configurations/tomcat7x/webapps/common.war | grep app
2342 Wed Jul 16 20:28:32 PDT 2014 WEB-INF/classes/applicationContext.xml
➜ comma git:(S120297) ✗ 但是当我运行测试时,我认为失败是
Tests in error:
readCache(com.org.comma.integration.ITCache): IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist 我还试着把我的测试注释为
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration (locations = "classpath*:/applicationContext*.xml")
public class ITCache extends AbstractIntegrationTest { 但仍然是同一个问题
这里出什么问题了?
更新
我的web.xml有如下条目
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>发布于 2014-07-17 19:31:39
正如错误所述,在类路径中找不到该文件,请确保您的文件位于类路径的根目录中,您可以将applicationContext文件添加到资源文件夹并启动安装。我有相同的代码,它的工作,web.xml与启动测试没有任何关系,其他事情--如何启动测试--您可以做的很重要--抛出maven或者直接使用eclipse。我们用maven启动测试,它是生成资源的,而不是其他方式。
https://stackoverflow.com/questions/24808196
复制相似问题