Eclipse无法找到Spring配置文件

use*_*934 3 java spring dependency-injection spring-mvc

我在Spring中弄湿手,并使用Eclipse和Spring.我用eclipse编写了一个非常简单的Spring应用程序来在bean中注入一个属性.但是,当我运行我的应用程序时,Spring正在抛出异常,似乎Spring无法找到Spring配置文件.下面是堆栈跟踪 -

INFO: Loading XML bean definitions from class path resource [Beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [Beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [Beans.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
Run Code Online (Sandbox Code Playgroud)

我尝试了以下内容 - 在ClassPathXmlApplicationContext方法中给出完整路径,如 -

ApplicationContext context = new ClassPathXmlApplicationContext("C:/Users/devshankhasharm/workspace/FinalPowerShell/src/src/main/Beans.xml");
Run Code Online (Sandbox Code Playgroud)

我还更新了Windows中的ClassPath变量,为我的spring配置文件添加了路径.但没有任何效果.任何想法都将受到高度赞赏.

Ale*_*r M 8

试试这个

ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:Beans.xml");
Run Code Online (Sandbox Code Playgroud)

当然,你Beans.xml必须在课堂上.

更新或者可能

ApplicationContext context = new ClassPathXmlApplicationContext("file:src/main/Beans.xml");
Run Code Online (Sandbox Code Playgroud)