Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
来源:互联网 发布:台湾中视直播软件 编辑:程序博客网 时间:2024/05/29 04:48
今天在做java main函数调用注入到spring容器中的方法时报了一个错误,如下:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not existat org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)at com.b505.weixin.utils.Test.main(Test.java:27)Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not existat org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)... 13 more
报这种错误的原因就是:加载spring配置文件时路径 路径出现错误了;
注意:java中加载spring配置文件applicationContext.xml或者bean.xml时,要将这两个文件放在系统的根目录下(即src下),只有这样在加载时才不会出现错误。
下面是文件放在根目录下的加载方法
String paths[]={"applicationContext.xml","applicationContext-security.xml"};//加载spring的配置文件ApplicationContext context=new ClassPathXmlApplicationContext(paths);
需要注意的是当加载多个spring配置文件时要用数
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.
还有一点要注意,当applicationContext.xml配置文件放在src/main/resources/spring路径下,加载的要这样写
String paths[]={"spring/applicationContext.xml","spring/applicationContext-security.xml"};//加载spring的配置文件ApplicationContext context=new ClassPathXmlApplicationContext(paths);AccessTokenUtil atu=(AccessTokenUtil) context.getBean(AccessTokenUtil.class);
否则就会报错:java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exit.
0 0
- Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
- Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
- Caused by: java.io.FileNotFoundException: class path resource [com/ncs/bean/News.hbm.xml] cannot be
- java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because
- ssh整合是Caused by: java.io.FileNotFoundException: class path resource [bean/test/User.hbm.xml] cannot
- FAQ(19):java.io.FileNotFoundException: class path resource [resources/applicationContext.xml] cannot
- 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 [XXXXX.xml] cannot be opened
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not
- java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
- java.io.FileNotFoundException: class path resource [bean.xml] cannot be opened because it does not e
- java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened
- 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
- Causes for java.io.FileNotFoundException: class path resource [hibernat.xml] cannot be opened becaus
- 局域网连接sql--SQL Server 2008
- javascript笔记:自己写一个jqgrid框架(一)
- 机器学习入门(14)--逻辑回归(2)
- Linux Centos 迁移Mysql 数据位置
- IP地址与子网掩码做逐位与运算
- Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope
- ViewGroup和View以及TouchDelegate的触摸事件源码简析
- 构建故障隔离的架构
- spark与kafka连接测试
- VS13里写C遇到的一些问题
- 字符反转
- BZOJ2748(DP)
- RecyclerView简单解析
- ZooKeeper的安装和部署