java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
来源:互联网 发布:java中断 原理 编辑:程序博客网 时间:2024/05/29 02:32
ava.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exit.
在用maven管理的spring项目中做单元测试时候,加载不了spring的配置文件。出现该问题的原因是,用maven创建的项目,必须把spring的配置文件beans.xml或者applicationContext.xml放到系统根目录下,做单元测试时候用
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("beans.xml"); Girl girl=(Girl)applicationContext.getBean("girl");才能正确加载spring的配置文件,才能正确获取bean。不知道这个定律在其他电脑的环境下是否适合,撸主在两台计算机上都是通过这种方式配好的。
maven项目的系统根目录默认是src/main/java和src/main/resources,而不是src,所以beans.xml文件必须放到 src/main/java和src/main/resources 下面的文件夹或者包中,否则就会报上面的错误: java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exit.
还有一点,要注意的是,如果beans.xml不是直接放到了 src/main/java和src/main/resources路径下,在读取beans文件时候,还要加上路径,如beans.xml放在了 src/main/java/conf路径下,那么加载时候要这样写:
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("conf/beans.xml");
否则就会报错: java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exit.
而下面这种写法,是把 beans.xml直接放到了 src/main/java和src/main/resources路径下
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("beans.xml");
- java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
- java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
- java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
- java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened be
- java.io.FileNotFoundException: class path resource [spring/ApplicationCont.xml] cannot be opened be
- java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened b
- 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
- [SSM/Junit]java.io.FileNotFoundException: class path resource [spring-mybatis.xml] cannot be opened
- java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because
- Causes for java.io.FileNotFoundException: class path resource [hibernat.xml] cannot be opened becaus
- 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 ..cannot be opened because it does not exist
- Caused by: java.io.FileNotFoundException: class path resource [com/ncs/bean/News.hbm.xml] cannot be
- Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
- HttpURLConnection 访问网页异常 问题的解决方法
- 大数据IMF传奇行动 IDEA导入spark源代码! 走入spark源代码世界!
- hashset hashcode们
- hdu1664 Different Digits
- 表单数据集定义
- java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
- Java序列求和
- jQuery15(元素each方法,表单选择器)
- <Java设计模式>—抽象工厂模式
- 选项卡组件定义
- Linux目录遍历实现 -- 列出当前目录下所有文件
- 树定义
- hibernate.cfg.xml
- 记CentOS 7环境下安装g++