1. 程式人生 > >class path resource [spring.xml] cannot be opened because it does not exist

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

    使用maven建立web工程,將spring配置檔案applicationContext.xml放在src/resource下,用Myeclipse編譯時提示class path resource [applicationContext.xml] cannot be opened because it does not exist錯誤。

web.xml配置的如下

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

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

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