我在Spring中弄溼了我的手,並與Spring一起使用Eclipse。我已經用eclipse寫了一個非常簡單的Spring應用程序來在bean中注入一個屬性。但是,當我運行我的應用程序時,Spring正在拋出異常,並且Spring似乎無法找到Spring配置文件。下面是堆棧跟蹤 -Eclipse無法找到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)
我曾嘗試以下 - 給在ClassPathXmlApplicationContext的方法類似的完整路徑 -
ApplicationContext context = new ClassPathXmlApplicationContext("C:/Users/devshankhasharm/workspace/FinalPowerShell/src/src/main/Beans.xml");
我也更新了CLASSPATH變量在Windows中添加我的彈簧配置文件的路徑。但沒有任何工作。任何想法將不勝感激。
由於錯誤提示您需要在classpath中有beans.xml,而您沒有,所以無法使用ClassPathXmlApplicationContext的完整路徑。請發佈你的項目結構和bean.xml的位置,如果你正在運行tomcat,那麼beans.xml會出現在web-inf/classes中 – Subin
正如我上面提到的,我在windows中添加了classpath變量來包含Spring配置xml文件。有沒有什麼需要在Eclipse中完成更新類路徑來獲取我的配置文件。 – user496934
yes右鍵單擊eclipse項目,選擇build path-> configure build path並檢查Source是否具有beans.xml所在的文件夾。我認爲windows中的類路徑環境變量不被認爲是通過eclipse計算類路徑 – Subin