IOException从类路径资源[beans1.xml]解析XML文档; 嵌套异常是java.io.FileNotFoundException

KIt*_*tis 1 java spring dependency-injection

当我尝试运行简单的弹簧示例时,我正在超越异常

下面的代码行尝试从beans1.xml中读取spring bean

ApplicationContext context = new ClassPathXmlApplicationContext("beans1.xml");
Run Code Online (Sandbox Code Playgroud)

以下是我得到的完整例外情况.

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
Run Code Online (Sandbox Code Playgroud)

我已将xml文件放在每个可能的位置,希望该程序将检测该文件.但是这个程序仍然找不到这个bean配置文件.我也使用maven作为构建工具,但我使用Eclipse IDE运行程序

Jig*_*shi 6

把它放在resourcesmaven项目目录中

src/main/resources/beans1.xml
Run Code Online (Sandbox Code Playgroud)