class path resource [applicationContext.xml] cannot be opened because it does not exist

maven創建web工程Spring配置文件找不到問題解決方案

使用maven創建web工程,將spring配置文件applicationContext.xml放在src/resource下,編譯時提示class path resource [applicationContext.xml] cannot be opened because it does not exist錯誤。但是用mvn clean package命令編譯時成功的。

web配置文件

 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
 </context-param>

 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

發現是由於classpath不是指向resource路徑,導致一直找不到文件。需要在classpath後面加個*,這樣就解決問題了。

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>


發佈了29 篇原創文章 · 獲贊 20 · 訪問量 18萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章