2016-06-22 32 views
0

我是Spring和Hibernate的新手。我做了一本書Prospring4 的項目但我沒有一個簡單的java應用程序,但動態web項目(未來)。我寫了所有的代碼,並創建了一個帶有bean的app-context-annotation.xml。在本書中,我有一個代碼加載:Eclipse Spring動態web項目classpath查找xml配置

GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); 
ctx.load("classpath:META-INF/spring/app-context-annotation.xml"); 

在我的項目我有一個非標準路徑 - WebContent/META-INF我添加文件夾文件的位置。但總是我得到一個錯誤:

org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [META-INF/spring/app-context-annotation.xml] Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/spring/app-context-annotation.xml]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/spring/app-context-annotation.xml] cannot be opened because it does not exist

我看了很多論壇的答案,但我真的不明白爲什麼會發生! 我試圖將我的項目轉換爲Maven項目,但又得到了這個錯誤。

PLZ告訴我我做錯了什麼?

編輯。 好的。現在這是我的項目結構,但結果是相同的例外。

enter image description here

+0

[Pro Spring 3book,class path resource \ [app-context-annotation.xml \]無法打開,因爲它不存在](http://stackoverflow.com/問題/ 10971077/pro-spring-3book-class-path-resource-app-context-annotation-xml-can-be-ope) – Destrif

+0

No.因爲沒有DYnamic web項目,我沒有這些文件夾 – R1K0

回答

0

是在classpath Webcontent文件夾的?我的意思是,當你建立你的項目時,你會看到app-context-annotation.xml到classes文件夾中?如果沒有,則應將Webcontent文件夾添加到構建路徑或將xml移動到另一個文件夾。 pe:src/main/java

+0

我編輯問題。你的意思是 - 在我的班級路線中 - 我需要檢查它嗎? – R1K0