1

当我尝试运行简单的弹簧示例时,我遇到了异常

以下代码行尝试从 beans1.xml 读取 spring beans

ApplicationContext 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 运行程序

4

2 回答 2

6

放到resourcesmaven项目目录下

src/main/resources/beans1.xml
于 2012-12-06T02:53:36.040 回答
0

检查名称,您的 bean.xml 文件名应与您在此处提到的相同,即 beans.xml ClassPathXmlApplicationContext("beans1.xml"):

于 2013-06-20T06:48:47.913 回答