java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
来源:互联网 发布:淘宝怎么选发货地 编辑:程序博客网 时间:2024/05/29 03:08
java.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
- XMLSchema 模式与命名空间
- ORACLE INSTANT CLIENT和PLSQL的配置
- 排序算法总结
- 设计模式——单例模式(Singleton)
- SAS学习笔记之_N_
- java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
- ZOJ - 1203 Swordfish (最小生成树 Prim)
- jQuery的deferred对象详解
- SQL中 decode()函数简介
- java中的static
- 液晶LCD1602实验
- 疯狂java_chap6
- page,request,session,application四个域对象的使用区别
- Problem G