当我尝试运行简单的弹簧示例
时,我遇到了异常以下代码行尝试从beans1.xml
中读取spring beanApplicationContext context = new ClassPathXmlApplicationContext("beans1.xml");
以下是我得到的完整例外情况。
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
我已将xml文件放在每个可能的位置,希望该程序将检测该文件。但是这个程序仍然找不到这个bean配置文件。我也使用maven作为构建工具,但我正在使用Eclipse IDE
运行程序答案 0 :(得分:6)
将其放在maven项目的resources
目录中
src/main/resources/beans1.xml
答案 1 :(得分:0)
检查名称,你的bean.xml文件名应该与你在这里提到的相同,即。,beans.xml ClassPathXmlApplicationContext(“beans1.xml”):