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>