我以前在这里看过这个问题,但是没有能够找出问题。我在我的Java项目和xml文件中使用spring,虽然它存在但是找不到。
INFO: Loading XML bean definitions from URL [file:/cs373p1Facilitiesold/resources/FaciltiesContext.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/cs373p1Facilitiesold/resources/FaciltiesContext.xml]; nested exception is java.io.FileNotFoundException: \cs373p1Facilitiesold\resources\FaciltiesContext.xml (The system cannot find the path specified)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:613)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at main.view.FacilityMain.main(FacilityMain.java:22)
Caused by: java.io.FileNotFoundException: \cs373p1Facilitiesold\resources\FaciltiesContext.xml (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
这是我的.classpath
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
这是我实例化应用程序上下文的代码
ApplicationContext factory = new ClassPathXmlApplicationContext("file:/cs373p1Facilitiesold/resources/FaciltiesContext.xml");
答案 0 :(得分:0)
当您使用 ClassPath XmlApplicationContext时,无需在路径中使用file://或/ resources /。
下面的代码可以使用。
ApplicationContext factory = new ClassPathXmlApplicationContext("FaciltiesContext.xml")
答案 1 :(得分:0)
编译项目时,java
和resource
文件夹中的所有内容都会转到根目录。因此无需指定完整的位置。
只需输入文件名即可。
ApplicationContext factory = new ClassPathXmlApplicationContext("FaciltiesContext.xml");