nested exception is java.io.FileNotFoundException: class path resource [spring/spring-datasource-mog
spring单元測试时发现的问题:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/spring-datasource-mogon.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/spring-datasource-mogon.xml]
cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.test.db.mongo.test.MongoTest.setUp(MongoTest.java:32)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.io.FileNotFoundException: class path resource [spring/spring-datasource-mogon.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 26 morez
载入配置文件的代码例如以下:
ApplicationContext context = new ClassPathXmlApplicationContext("spring/spring-datasource-mogon.xml");
之前在写单元測试时也遇到过类似的问题,查询、核对代码和载入方式都没有问题,就是报错找不到文件。百思不得其解,一直以为是和环境相关。
今天在调试mongo时,最终找到问题所在了
出现故障的情况:仅仅要更新过、刷新过project,就会报如上错误;
解决的方法:
1. 新建一个内容同样,名字不同的配置文件;比如。将配置文件/spring-datasource-mogon.xml的名字改动为/spring-datasource-mogon-1.xm
2. 改动代码的载入配置文件为:ApplicationContext context = new ClassPathXmlApplicationContext("spring/spring-datasource-mogon-1.xml");
3. 调试。发现没有上述问题了。
问题总结:
1. 更新project后,单元測试载入的project也会刷新,刷新的时候配置文件从project环境中删掉了。
2. 改动名字。相当于加入了一个新的文件,这时project环境中会跟着同步。
3. 因此程序在载入新文件时能够找到。老的找不到。
4. 单元測试载入的配置文件的路径没有找到。假设找到了能够直接将老配置文件加入到当中
5. 遗留问题: 问什么刷新project时,会将配置文件所有清空;这个怎样避免
6. project的编辑存放路径和project执行环境路径的差别是什么,project执行环境路径是什么。
nested exception is java.io.FileNotFoundException: class path resource [spring/spring-datasource-mog的更多相关文章
- 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 ...
- parsing XML document from class path resource [applicationtext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationtext.xml] cannot be opened because it does not e
控制台异常: parsing XML document from class path resource [applicationtext.xml]; nested exception is java ...
- nested exception is java.io.FileNotFoundException: class path resource [jdbc.properties] cannot be opened because it does not exist
Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [j ...
- nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may ...
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: c
//这个是 配置文件放错了地方 org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing ...
- 解决CXF的java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml] cannot be opened because it does not exist
以下是错误信息 九月 25, 2017 8:22:04 下午 org.springframework.web.context.support.XmlWebApplicationContext prep ...
- Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
1.错误描述 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.tes ...
- Caused by: java.io.FileNotFoundException: class path resource [spring/springmvc.xml] cannot be opene
Caused by: java.io.FileNotFoundException: class path resource [spring/springmvc. ...
- 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中document.all 的用法
1. document.all是什么? document.all 实质就是文档中所有元素的集合.可以看做一个数组. 2.document.all怎么用? 2.1 根据下标取元素. 语法: docu ...
- Page 16 Exercises 1.2.3 -------Introduction to Software Testing (Paul Ammann and Jeff Offutt)
Below are four faulty programs. Each includes a test case that results in failure. Answer the follow ...
- Ubuntu14.04LTS安装记录(办公室联想台式机)
一.用UltraISO制作U盘启动器,被安装的电脑要设置成从U盘启动. 二.傻瓜式安装简体中文版 三.安装更新 sudo apt-get update sudo apt-get upgrade 四.安 ...
- 在logopond中看到的优秀设计随想
本随笔仅仅只是自己对于设计作品的想法,不喜勿喷~ 昨日看到关于大神配色的文章,决定在logopond网站中看看优秀的作品,以为自己的配色找找灵感,学习学习,对自己有很强的震撼力的有: 以女性高跟性的抽 ...
- 演义江湖PC端意见汇总
写在前面: 1.自己的游戏自己玩玩爽不爽,自己爽了才能说玩家可能会接受,自己都玩不下去玩家凭什么玩你的游戏 2.如果你负责美术,那么你到游戏中看看,你如果不能接受,玩家也会觉得游戏很丑 3.如果你负责 ...
- 第二百二十六天 how can I 坚持
今天弟弟生日,只是简单的说了句生日快乐,幸亏看了下日历,要不又忘了. 在家待了一天. 明天还想去爬山,八大处太远了,该去哪呢. 不想在家待着. 日复一日,啊,年复一年啊.想想好可怕,人生,太快.该如何 ...
- C#.Net 导出Excel 之单元格 相关设置
range.NumberFormatLocal = "@"; //设置单元格格式为文本range = (Range)worksheet.get_Range("A1 ...
- tomcat的host配置
本机 etc\hosts 首先了解C:\WINDOWS\system32\drivers\etc\hosts文件配置 127.0.0.1 static1.ezsins.com #adoble ps c ...
- ems server
自DELPHI XE7始提供企业移动服务,方便移动等设备通过REST+JSON访问中间件提供的服务. EMS (Enterprise Mobility Services企业移动服务) 服务器给EMS客 ...
- Java抽象类和内部类
类(class) 类是相似对象中共同属性和方法的集合体 在面向对象中定义类,就是在描述事物,就是在定义属性(变量)和行为(方法).属性和行为共同成为类中的成员(成员变量和成员方法). 封装.继承和多态 ...