IDEA中Spring配置错误:class path resource [.xml] cannot be opened because it does not exist
来源:互联网 发布:等一分钟网络女歌手 编辑:程序博客网 时间:2024/05/21 03:15
如果在运行 Spring 项目时出现了类似于:
class path resource [applicationContext.xml] cannot be opened because it does not exist
这样的异常
意思就是没有找到你的 .xml 配置文件
原因
我可以肯定你一定用的是
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
来获取配置文件
ClassPathXmlApplicationContext( ) 方法是在其所在的目录中寻找 .xml 配置文件
注意: 这里指的是编译后的 .class 文件所在的目录,不是 .java 文件
出现异常时,我的项目结构时这样的:
请注意我用红线标注的地方:
此时 applicationContext.xml 文件在 src 目录下
造成异常的原因是 IDEA 默认的项目结构导致的,它将 .java 文件和 .class 文件分开存放,.java文件存于 src 中,.class 文件存于 target 中
因此,ClassPathXmlApplicationContext( ) 方法无法找到 applicationContext.xml
解决方法
知道了原因,那么我们就需要把 .class 也放进 src 目录中
注意:不能直接把 applicationContext.xml 移至 target 目录下,因为 .xml 配置文件运行时也需要在 .java 文件中获取属性信息
点击 File -> Project Structure(或快捷键 Ctrl+Alt+Shift+S)
然后修改 Output Path 到 src 目录下即可:
阅读全文
0 0
- IDEA中Spring配置错误:class path resource [.xml] cannot be opened because it does not exist
- class path resource [spring.xml] cannot be opened because it does not exist
- Spring问题:class path resource [xxx.xml] cannot be opened because it does not exist
- class path resource [spring-mvc.xml] cannot be opened because it does not exist
- 关于class path resource [applicationContext.xml] cannot be opened because it does not exist
- class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist
- class path resource [applicationContext.xml] cannot be opened because it does not exist
- class path resource [applicationContext.xml] cannot be opened because it does not exist
- spring class path resource [jdbc.properties] cannot be opened because it does not exist
- class path resource [spring.xml] cannot be opened because it does no exist;
- java.io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not
- java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist
- java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist 解决方法
- eclipse项目报错怎么解决class path resource [beans.xml] cannot be opened because it does not exist
- Spring问题:class path resource [org.spring/applicationContext.xml] cannot be opened because it does no
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not
- 文章标题
- 安卓问题——关于TableLayout
- 大数据 (二十四)Hive【Hive 正则匹配】
- Oracle-序列
- 如何解决Eclipse按"alt+/"后闪屏(窗口闪个不停/不停抖动)的问题
- IDEA中Spring配置错误:class path resource [.xml] cannot be opened because it does not exist
- NLP 中的embedding layer
- vi 全部命令
- 【图论】[luoguP1330]封锁阳光大学
- BZOJ1025(SCOI2009)[游戏]--线性筛+DP
- MySQL 第八篇:自定义函数、存储过程、游标
- 动态规划-背包问题、兑换零钱问题、旅行商问题
- pandas中使用三元表达式
- oracle死锁