-1

我正在尝试在 Eclipse 上创建一个带有 spring 的你好世界。但我得到下一个错误:

INFO: Loading XML bean definitions from class path resource  
[src/com/spr/main/contextApplication.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [src/com/spr/main/contextApplication.xml]; nested exception is java.io.FileNotFoundException: class path resource [src/com/spr/main/contextApplication.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)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
at com.spr.main.Main.main(Main.java:15)
Caused by: java.io.FileNotFoundException: class path resource [src/com/spr/main/contextApplication.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 4 more

我试过了 :

XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("\\src\\com\\spr\\main\\contextApplication.xml"));

XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("\\src\\com\\spr\\main\\contextApplication.xml"));

并且 contextApplication.xml 路径是 src/com/spr/main/

4

1 回答 1

2

更改您的声明

XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("\\src\\com\\spr\\main\\contextApplication.xml"));

XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("com\\spr\\main\\contextApplication.xml"));

不要忘记检查文件名。

于 2013-02-05T10:50:55.230 回答