Caused by: java.io.FileNotFoundException:... cannot be opened because it does not exist
2014-10-13 13:17
513 查看
初学Spring,配置了applicationContext.xml后,测试时出现了这样的错误:
这应该是编译路径的问题;
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); PersonBean bean = (PersonBean)ctx.getBean("userBean"); bean.show();
Caused by: java.io.FileNotFoundException: class path resource [com/bless/common/spring/springApplicationContext.xml] cannot be opened because it does not exist
这应该是编译路径的问题;
使用new ClassPathXmlApplicationContext("applicationContext.xml"); 来读取时,将applicationContext.xml放到/WEB-INF/classes目录下; 或放到src目录下,
// ClassPathXmlApplicationContext 是读取 src 目录下的配置文件 ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext.xml"); // FileSystemXmlApplicationContext 即系统文件路径,文件的目录。 ApplicationContext context = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/applicationContext.xml");
相关文章推荐
- java.io.FileNotFoundException: [WEB-INF/spring-servlet.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 [META-INF/xfire/services.xml] cannot be opened because it does not exist
- 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 [bean/test/User.hbm.xml] 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 [spring.xml] cannot be opened because it does not
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not
- Spring错误:java.io.FileNotFoundException: class path resource ..cannot be opened because it does not e
- java.io.FileNotFoundException: class path resource [bean.xml] cannot be opened because it does not e
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not
- java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because
- java.io.FileNotFoundException: class path resource [WEB-INF/classes/cn/golaxy/yqpt/pojo/] cannot be resolved to URL because it
- java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
- [SSM/Junit]java.io.FileNotFoundException: class path resource [spring-mybatis.xml] cannot be opened
- java.io.FileNotFoundException class path resource [xxx.xml] cannot be opened
- Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
- 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 b