2013-02-05 222 views
-1

我試圖在日食上用spring創建一個hello world。但我得到了一個錯誤:Hello World with 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 /主/

+0

給出錯誤的代碼是什麼? –

回答

2

更改您的聲明

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

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

不要忘了查看文件名。

+0

Thxs現在工作正常 – Jjreina

+0

偉大的祝賀去接受。 –

+1

他的意思是「接受這個答案」 - 習慣上,在StackOverflow上,標記爲「接受」滿足您的問題的答案。這樣做會提高花時間回答的人的聲譽,如果你不經常這樣做,人們就會停止回答你的問題。 – arcy