IOException 从类路径资源 [beans1.xml] 解析 XML 文档;嵌套异常是 java.io.FileNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13735998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IOException parsing XML document from class path resource [beans1.xml]; nested exception is java.io.FileNotFoundException
提问by KItis
I am getting above exception when i try to run simple spring example
当我尝试运行简单的 spring 示例时,我遇到了异常
Following line of code try to read spring beans from beans1.xml
以下代码行尝试从 beans1.xml 读取 spring beans
ApplicationContext context = new ClassPathXmlApplicationContext("beans1.xml");
Following is the complete exception i am getting.
以下是我得到的完整异常。
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans1.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans1.xml] cannot be opened because it does not exist
I have put xml file in every possible location hoping that program will detect the file. But still this program can not find this bean configuration file. Also i am using maven as the build tool, but i am running the program using Eclipse IDE
我已将 xml 文件放在每个可能的位置,希望该程序能够检测到该文件。但是这个程序还是找不到这个bean配置文件。我也使用 maven 作为构建工具,但我使用 Eclipse IDE 运行程序
回答by Jigar Joshi
put it in resources
directory of maven project
放在resources
maven项目目录下
src/main/resources/beans1.xml
回答by user2497599
check the name,your bean.xml file name should be same as what you have mentioned here ie., beans.xml ClassPathXmlApplicationContext("beans1.xml"):
检查名称,您的 bean.xml 文件名应该与您在这里提到的相同,即 beans.xml ClassPathXmlApplicationContext("beans1.xml"):