IDEA Junit FileNotFoundException: class path resource [spring/spring.xml] cannot be opened because it does not exist
今天打算写一个单元测试,但是已经有写好的单元测试无论怎么弄都提示文件不存在,自己一度以为是启动方式不正确.这里简单记录一下处理过程
1 异常信息:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/spring.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/spring.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:253)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:122)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:109)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:261)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:68)
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:86)
... 24 more
Caused by: java.io.FileNotFoundException: class path resource [spring/spring.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
... 36 more
2 项目目录结构

3 处理方式
1. 首先是获取单元测试工作目录
@Test
public void demoTest(){
System.out.println(AccountTest.class.getClassLoader().getResource("").getPath());
}
输出信息:
/D:/git/zzlh/guarantee/target/test-classes/
2. 然后去这个目录下查找是否有自己的配置文件 -> spring/spring.xml
发现确实没有,这时我想到是不是IDEA的原因,之前用eclipse也常是这种因为build path的原因造成文件找不到
3 IDEA需要你指定单元测试的resouces目录
a. 如果你test目录下有resouces目录文件,需要如下操作
确认 test/resources 目录为 [test/resources] --右键--> [Mark Directory as] -->[Test Resources Root]
b. 如果没有需要添加test的resource目录
File -> Project Structrue... -> Project Settings -> Modules 进行如下配置

IDEA Junit FileNotFoundException: class path resource [spring/spring.xml] cannot be opened because it does not exist的更多相关文章
- parsing XML document from class path resource [config/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [config/applicationContext.xml] 解决方案
parsing XML document from class path resource [config/applicationContext.xml]; nested exception is j ...
- idea的maven项目运行出错_java.io.FileNotFoundException: class path resource [spring/sprint-tx.xml] cannot be opened because it does not exist
前提:idea maven ssm 错误信息如下: 严重: Exception sending context initialized event to listener instance of ...
- spring整合mybatis错误:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist
spring 整合Mybatis 运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse 错误:class path reso ...
- class path resource [spring/ApplicationContext-springmvc.xml] cannot be opened because it does not exist
配置如下: <init-param> <param-name>contextConfigLocation</param-name> <param-va ...
- class path resource [spring/applicationContext.xml] cannot be opened because it does not exist
1.查看路径有没有写错 2.编辑器认为你的文件不是 source folders(原文件),需要你手动将文件改过来
- nested exception is java.io.FileNotFoundException: class path resource [spring/spring-datasource-mog
spring单元測试时发现的问题: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsin ...
- Caused by: java.io.FileNotFoundException: class path resource [spring/springmvc.xml] cannot be opene
Caused by: java.io.FileNotFoundException: class path resource [spring/springmvc. ...
- class path resource [processes/] cannot be resolved to URL because it does not exist
springboot整合activiti时报以下错误,原因是项目启动时检查流程文件 nested exception is java.io.FileNotFoundException: class p ...
- Spring报错:java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
感谢:http://blog.chinaunix.net/uid-20681545-id-184633.html提供的解决方案,非常棒 ! 问题说明: 新建一个Spring项目,新建一个Bean类:H ...
随机推荐
- js垃圾回收及内存泄漏
js垃圾回收 js能够自动回收申请却未使用的内存,由于每次清除需要的性能较大,不是时时在刷新,而是每隔一段时间才进行一次. 回收的两种方式 标记清除(常用) 在内存中先标记变量,然后清除那些那些进入环 ...
- jQuery标签操作
样式操作 样式类操作 //添加指定的css类名 $('元素选择器')addClass('类名'); //移除指定的css类名 removeClass(); //判断样式存不存在 hasClass(); ...
- Fortify漏洞之Open Redirect(开放式重定向)
继续对Fortify的漏洞进行总结,本篇主要针对 Open Redirect(开放式重定向) 的漏洞进行总结,如下: 1.1.产生原因: 通过重定向,Web 应用程序能够引导用户访问同一应用程序内 ...
- MVC-区域(Area)
1.启用路由前的准备工作 1.Global.asax.cs中注册路由 public class MvcApplication : System.Web.HttpApplication { protec ...
- 你的系统需要SMB2或者更高版本,才能访问共享
- Android笔记(十八) 下拉列表(Spinner)
App中常用的控件——下拉列表(Spinner),提供特定选择供用户选择 Spinner每次只能选择一个部件,它的选项来自于与之相关联的适配器(apater)中. MainActivity.java ...
- HTML的BODY内标签介绍
一.基本标签 <body> <b>加粗</b> <i>斜体</i> <u>下划线</u> <s>删除线& ...
- unittest 运行slenium(二)---打开浏览器及元素操作
一: 打开win10中安装的浏览器 1. 打开的浏览器有:谷歌/火狐/ie/edge 2. 当浏览器的driver没有配置在path环境下时,在启动浏览器时需要传入driver的所在位置 3. 其中火 ...
- Nginx的平滑升级记录---适用于编译安装的Nginx
一.查看自己的Nginx的版本号 [root@localhost sbin]# cd /usr/local/nginx/sbin/ [root@localhost sbin]# ls nginx [r ...
- VSCode安装程序——java开发
文章:微软为 Java 开发者推出 VSCode 安装程序 文章介绍微软为VSCode提供了开发程序,方便java开发者更好的使用VSCode