【发布时间】:2014-08-12 12:12:39
【问题描述】:
我知道这个关于 spring xml config file not found in execution 的问题之前已经被问过好几次了,但其他答案似乎都不适合我。
我正在尝试使用 Spring 和 JUnit 在 Maven 项目中运行一些测试,但我一直收到此错误:
T E S T S 运行 es.udc.jcastedo.NosaTenda.test.model.productoService.ProductoServiceTest 12-ago-2014 13:37:33 org.springframework.test.context.TestContextManager retrieveTestExecutionListeners 信息:无法实例化 TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]。指定自定义侦听器类或使默认侦听器类(及其所需的依赖项)可用。违规类:[javax/servlet/ServletContext] 12-ago-2014 13:37:33 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh 信息:刷新 org.springframework.context.support.ClassPathXmlApplicationContext@2f8bbc98:启动日期 [Tue Aug 12 13:37:33 CEST 2014];上下文层次的根 12-ago-2014 13:37:33 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions 信息:从类路径资源 [nosaTenda-spring-config.xml] 加载 XML bean 定义 测试运行:2,失败:0,错误:2,跳过:0,经过时间:0.225 秒
结果:
测试错误: es.udc.jcastedo.NosaTenda.test.model.productoService.ProductoServiceTest es.udc.jcastedo.NosaTenda.test.model.productoService.ProductoServiceTest:无法初始化类 es.udc.jcastedo.NosaTenda.test.model.util.DbUtil
测试运行:2,失败:0,错误:2,跳过:0
这是肯定报告完整跟踪的链接:https://dl.dropboxusercontent.com/u/2635926/es.udc.jcastedo.NosaTenda.test.model.productoService.ProductoServiceTest.txt
在哪里可以找到这些行:
原因:org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [nosaTenda-spring-config.xml];嵌套异常是 java.io.FileNotFoundException: 类路径资源 [nosaTenda-spring-config.xml] 无法打开,因为它不存在
原因:java.io.FileNotFoundException:类路径资源[nosaTenda-spring-config.xml]无法打开,因为它不存在
es.udc.jcastedo.NosaTenda.test.model.productoService.ProductoServiceTest 已用时间:0.003 秒
DbUtil 是一个被所有测试调用的辅助类,上下文被初始化:
public class DbUtil {
static {
ApplicationContext context = new ClassPathXmlApplicationContext("nosaTenda-spring-config.xml");
transactionManager = (PlatformTransactionManager) context
.getBean("transactionManager");
productoDao = (ProductoDao) context.getBean("productoDao");
tiendaDao = (TiendaDao) context.getBean("tiendaDao");
}
...
public static void populateDb() {
...
}
public static void cleanDb() throws Throwable {
...
}
}
显然存在问题,因为似乎无论如何都找不到 xml 配置文件,并且它在 ClassPathXmlApplicationContext 方法调用时中断。
理论上,spring 配置文件应该在 src/main/resources 中。
我尝试了所有组合,从限定名称“/NosaTenda/src/main/resources/nosaTenda-spring-config.xml”到“nosaTenda-spring-config.xml”,结果相同。
我不知道类路径出了什么问题,或者问题是否出在其他地方。
编辑
这是项目的 pom,我只记得我在 build-resources 部分添加了一些过滤,也许我在那里做错了什么,这就是问题所在。
【问题讨论】:
标签: java xml spring maven junit4