java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist
来源:互联网 发布:linux yum 编辑:程序博客网 时间:2024/06/12 10:23
初学Spring在用Resource rs=new ClassPathResource("applicationContext.xml");时老是遇到这个错误。后来发现用ApplicationContext ctx=new FileSystemXmlApplicationContext("WebContent/WEB-INF/applicationContext.xml");可以解决这个问题
仔细研究了下:之所以我用ClassPathResource中找不到applicationContext.xml是因为这个xml文件在建工程的时候默认放在了WebContent/WEB-INF/下面,但是用ClassPathResource是在当前目录也就是这个java文件所在的目录下进行寻找。因此把这个xml文件移动到src目录下面就ok了。
同理如果是用ApplicationContext ctx=new ClassPathXmlApplicationContext()也是这样是从当前路径寻找,xml文件应在当前目录下。
如果用FileSystemXmlApplicationContext呢,它是根据指定的路径来进行寻找,所以要把路径写完整。现在xml路径在src文件夹下。那就要写:ApplicationContext ctx=new FileSystemXmlApplicationContext("src/applicationContext.xml");这是比较直接简单的写法,后来又查了查发现对于FileSystemXmlApplicationContext也可以采用:1.加上classpath:前缀(这个时候xml要放在当前目录也就是src下)
ApplicationContext ctx=new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
2.加上file:把路径写全(用这个方法xml可以放任意地方)
ApplicationContext ctx=new ClassPathXmlApplicationContext("ApplicationContext ctx=new ClassPathXmlApplicationContext("file:F:/workspace/SpringExercis/src/applicationContext.xml");
阅读全文
0 0
- 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 解决方法
- 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
- java.io.FileNotFoundException: class path resource [bean.xml] cannot be opened because it does not e
- java.io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not
- Caused by: java.io.FileNotFoundException:... 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
- 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 not exist
- class path resource [applicationContext.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 [applicationContext.xml] cannot be opened because it does not exist
- class path resource [spring-mvc.xml] cannot be opened because it does not exist
- eclipse项目报错怎么解决class path resource [beans.xml] cannot be opened because it does not exist
- IDEA中Spring配置错误:class path resource [.xml] cannot be opened because it does not exist
- 边缘检测︱基于 HED网络TensorFlow 和 OpenCV 实现图片边缘检测
- ASP.NET-缓存技术
- XRecyclerView分割线多了一个的问题
- MATLAB 数组点积示例
- TortoiseSVN更改SVN服务器IP地址
- java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist
- leetcode String to Integer (atoi)(Java)
- test
- 关于.ocx和.dll控件注册遇到的问题记录
- 【C++】【LeetCode】28. Implement strStr()
- android动态拼接生成界面 ,大量界面
- MyBatis简介
- 移动团队内部BUG数减少的管理
- Error:A problem occurred configuring project ':app'.